Subscribe to this thread
Home - General / All posts - A three band, RGB version of the 3x3 Prewitt filter
Dimitri


5,491 post(s)
#12-Feb-19 10:04

You can download the samples and query mentioned here from the product downloads page, where there is a new RGB_Filter_Examples.mxb file for download.

Here's an RGB version of the 3x3 Prewitt filter previously discussed in connection with custom filters. The query text comes after the images in this post. It follows the same basic structure as the RGB version of the 5x5 Unsharp filter, but it has had to have the processtile and processRGB functions adjusted to take not one, but two filter arguments since the Prewitt filter uses two filter matrices in the computation. The adjusted functions are named processtile2f and processRGB2f.

Since the Prewitt filter uses 3x3 matrices, the value for @radius also was changed from 2 (for a 5x5 matrix) to 1 (for a 3x3 matrix).

The example project also has an RGB Sobel filter, which is the same as the Prewitt except for using different filter matrices.

Examples:

Original st_peters image.

st_peters after applying the RGB Prewitt filter.

Original sample image.

Sample after applying the RGB Prewitt filter.

Query text:

-- $manifold$

--

-- Template for custom dual filters

-- using parameters for filter and radius, and a function

--

-- Prewitt Edge Detect Filter 1

VALUE @filter1 TILE = StringJsonTile('[ -1, 0, 1, -1, 0, 1, -1, 0, 1 ]', 3, 3, 1, true);

-- Prewitt Edge Detect Filter 2

VALUE @filter2 TILE = StringJsonTile('[ -1, -1, -1, 0, 0, 0, 1, 1, 1 ]', 3, 3, 1, true);

VALUE @radius UINT8 = 1;

CREATE TABLE [RGB_Prewitt] (

  [X] INT32,

  [Y] INT32,

  [Tile] TILE,

  [mfd_id] INT64,

  INDEX [mfd_id_x] BTREE ([mfd_id]),

  INDEX [X_Y_Tile_x] RTREE ([X][Y][Tile] TILESIZE (128,128) TILETYPE FLOAT64x3),

  PROPERTY 'FieldTileSize.Tile' '[ 128, 128 ]',

  PROPERTY 'FieldTileType.Tile' 'float64x3'

);

-- Do not forget to change the Rect values when using other images

CREATE IMAGE [RGB_Prewitt Image] (

  PROPERTY 'Table' '[RGB_Prewitt]',

  PROPERTY 'FieldTile' 'Tile',

  PROPERTY 'FieldX' 'X',

  PROPERTY 'FieldY' 'Y',

  PROPERTY 'Rect' '[ 0, 0, 1214, 862 ]'

);

FUNCTION processtile2f(@t TILE, @r UINT8, @f1 TILE, @f2 TILE) TILE AS (

  (TileFilter(@t, @r, @f1)^2 + TileFilter(@t, @r, @f2)^2)^0.5

END;

FUNCTION processRGB2f(@t TILE, @r UINT8, @f1 TILE, @f2 TILE) TILE AS (

TileChannelsConcat(

  processtile2f(TileChannel(@t,0), @r, @f1, @f2),

TileChannelsConcat(

  processtile2f(TileChannel(@t,1), @r, @f1, @f2),

  processtile2f(TileChannel(@t,2), @r, @f1, @f2)))

END;

PRAGMA ('progress.percentnext' = '100');

INSERT INTO [RGB_Prewitt] (

  [X][Y],

  [Tile]

SELECT

  [X][Y],

  CASTV ((TileRemoveBorder(processRGB2f(TileCutBorder([st_peters],

 VectorMakeX2([X][Y]), @radius), @radius, @filter1, @filter2), @radius)) AS FLOAT64)

FROM [st_peters]

THREADS SystemCpuCount();

TABLE CALL TileUpdatePyramids([RGB_Prewitt Image]);

Enjoy!

Attachments:
rgb_prewitt.png
RGB_prewitt_01.png
RGB_prewitt_02.png
rgb_st_peters.png

Manifold User Community Use Agreement Copyright (C) 2007-2017 Manifold Software Limited. All rights reserved.