2D convolution: gradient images

Sobel gradient image: gray-scale image example

Load gray-scale image

img = ReadImage["cat256x256.ppm"] ; RowBox[{RowBox[{scale,  , =,  , 1.5}], ;}]

Display image

ShowImage[img, scale] ;

[Graphics:../HTMLFiles/index_151.gif]

Sobel gradient image

Sobel row mask

SobelRow[] // TraditionalForm

( -1.`   -2.`   -1.` )            0.`    0.`    0.`            1.`    2.`    1.`

Sobel row gradient image (magnitude)

sr = Mask[img, SobelRow[]] // N ; ShowImage[sr, scale, .8Max[sr]] ;

[Graphics:../HTMLFiles/index_155.gif]

Sobel column mask

SobelColumn[] // TraditionalForm

( -1.`   0.`    1.`  )            -2.`   0.`    2.`            -1.`   0.`    1.`

Sobel column gradient image (magnitude)

sc = Mask[img, SobelColumn[]] // N ; ShowImage[sc, scale, .8Max[sc]] ;

[Graphics:../HTMLFiles/index_159.gif]

Sobel gradient image

tmp = Sqrt[sc^2 + sr^2] ; ShowImage[tmp, scale, .8Max[tmp]] ;

[Graphics:../HTMLFiles/index_161.gif]

Sobel gradient image: color image example

Load color image

img = ReadImage["flowers256x256.ppm"] ; RowBox[{RowBox[{scale,  , =,  , 1.5}], ;}]

Display image

ShowImage[img, scale] ;

[Graphics:../HTMLFiles/index_164.gif]

Sobel gradient image

Sobel row mask

SobelRow[] // TraditionalForm

( -1.`   -2.`   -1.` )            0.`    0.`    0.`            1.`    2.`    1.`

Sobel row gradient image (magnitude)

sr = Mask[img, SobelRow[]] // N ; ShowImage[sr, scale, .8Max[sr]] ;

[Graphics:../HTMLFiles/index_168.gif]

Sobel column mask

SobelColumn[] // TraditionalForm

( -1.`   0.`    1.`  )            -2.`   0.`    2.`            -1.`   0.`    1.`

Sobel column gradient image (magnitude)

sc = Mask[img, SobelColumn[]] // N ; ShowImage[sc, scale, .8Max[sc]] ;

[Graphics:../HTMLFiles/index_172.gif]

Sobel gradient image

tmp = Sqrt[sc^2 + sr^2] ; ShowImage[tmp, scale, .8Max[tmp]] ;

[Graphics:../HTMLFiles/index_174.gif]

Prewitt gradient image: gray-scale image example

Load gray-scale image

img = ReadImage["cat256x256.ppm"] ; RowBox[{RowBox[{scale,  , =,  , 1.5}], ;}]

Display image

ShowImage[img, scale] ;

[Graphics:../HTMLFiles/index_177.gif]

Prewitt gradient image

Prewitt row mask

PrewittRow[] // TraditionalForm

( -1   -1   -1 )            0    0    0            1    1    1

Prewitt row gradient image (magnitude)

pr = Mask[img, PrewittRow[]] // N ; ShowImage[pr, scale, .8Max[pr]] ;

[Graphics:../HTMLFiles/index_181.gif]

Prewitt column mask

PrewittColumn[] // TraditionalForm

( -1   0    1  )            -1   0    1            -1   0    1

Prewitt column gradient image (magnitude)

pc = Mask[img, PrewittColumn[]] // N ; ShowImage[pc, scale, .8Max[pc]] ;

[Graphics:../HTMLFiles/index_185.gif]

Prewitt gradient image

tmp = Sqrt[pc^2 + pr^2] ; ShowImage[tmp, scale, .8Max[tmp]] ;

[Graphics:../HTMLFiles/index_187.gif]

Prewitt gradient image: color image example

Load color image

img = ReadImage["flowers256x256.ppm"] ; RowBox[{RowBox[{scale,  , =,  , 1.5}], ;}]

Display image

ShowImage[img, scale] ;

[Graphics:../HTMLFiles/index_190.gif]

Prewitt gradient image

Prewitt row mask

PrewittRow[] // TraditionalForm

( -1   -1   -1 )            0    0    0            1    1    1

Prewitt row gradient image (magnitude)

pr = Mask[img, PrewittRow[]] // N ; ShowImage[pr, scale, .8Max[pr]] ;

[Graphics:../HTMLFiles/index_194.gif]

Prewitt column mask

PrewittColumn[] // TraditionalForm

( -1   0    1  )            -1   0    1            -1   0    1

Prewitt column gradient image (magnitude)

pc = Mask[img, PrewittColumn[]] // N ; ShowImage[pc, scale, .8Max[pc]] ;

[Graphics:../HTMLFiles/index_198.gif]

Prewitt gradient image

tmp = Sqrt[pc^2 + pr^2] ; ShowImage[tmp, scale, .8Max[tmp]] ;

[Graphics:../HTMLFiles/index_200.gif]


Created by Mathematica  (February 5, 2004)