Spatial Filtering And Convolution

Transcription

Spatial Filtering andConvolution

Spatial Filteringapply a filter (also sometimes called a kernel or mask)to an image

Spatial Filteringapply a filter (also sometimes called a kernel or mask)to an imagea new pixel value is calculated, one pixel at a time

Spatial Filteringapply a filter (also sometimes called a kernel or mask)to an imagea new pixel value is calculated, one pixel at a timethe neighbouring pixels influence the result

New Pixel Valuethe pixel at location (x, y) in the new image will havea value:

New Pixel Valuethe pixel at location (x, y) in the new image will havea value:s(x, y) w1 f(x-1, y-1) w2 f(x-1, y) w3 f(x-1, y 1) w4 f(x, y-1) w5 f(x, y) w6 f(x, y 1) w7 f(x 1, y-1) w8 f(x 1, y) w9 f(x 1, y 1)

New Imageslide the mask over by one pixel and repeatNOTE: original image requires a 1-pixel border beadded or else the new image will be smaller than theoriginal

ExampleFind the new pixel value.Multiply the values in the mask withthe corresponding values in theimage and add them together.The original imageThe 47133123120137138129122120139130125119113

ExampleFind the new pixel value.Multiply the values in the mask withthe corresponding values in theimage and add them together.The original imageNormalization factor.Equal1 over theThetomasksum of the elements in1 the 47133123120137138129122120139130125119113

ExampleFind the new pixel value.Multiply the values in the mask withthe corresponding values in theimage and add them together.The original imageThe 47133123120137138129122120139130125119113

ExampleFind the new pixel value.Multiply the values in the mask withthe corresponding values in theimage and add them together.The original imageThe 47133123120137138129122120139130125119113

ExampleFind the new pixel value.Multiply the values in the mask withthe corresponding values in theimage and add them together.The original imageThe 47133123120137138129122120139130125119113

ExampleFind the new pixel value.Multiply the values in the mask withthe corresponding values in theimage and add them together.The original imageThe 47133123120137138129122120139130125119113

ExampleFind the new pixel value.Multiply the values in the mask withthe corresponding values in theimage and add them together.The original imageThe 47133123120137138129122120139130125119113

ExampleFind the new pixel value.Multiply the values in the mask withthe corresponding values in theimage and add them together.The original imageThe 47133123120137138129122120139130125119113

ExampleFind the new pixel value.Multiply the values in the mask withthe corresponding values in theimage and add them together.The original imageThe 47133123120137138129122120139130125119113

ExampleFind the new pixel value.Multiply the values in the mask withthe corresponding values in theimage and add them together.The original imageThe 47133123120137138129122120139130125119113

ExampleFind the new pixel value.Multiply the values in the mask withthe corresponding values in theimage and add them together.The original imageThe 47133123120137138129122120139130125119113

ExampleThe result142142139141139135135130123

What did you just do?1/9111111111

What did you just do?1/9111111111this is the averagingmask!

What did you just do?1/9111111111this is the averagingmask!the result is to smoothout the image

Original image

Averaged image

this operator is known as convolution

this operator is known as convolutionone convolves an image with a filter

More complicated filters

Gaussian Filter

Gaussian Filter

What would a Gaussianfunction look likeexpressed as a 3x3mask?

3x3 Gaussiana Gaussian functionexpressed as a 3x3mask

3x3 Gaussian11/1621242121a Gaussian functionexpressed as a 3x3mask

Not all masks are 3x3

0.10.080.050.030.01

.650.420.230.10.110.250.460.710.920.71110.92x 111 0.080.10.110.10.080.050.030.01

Mask Sizesthe larger the mask, the greater the effect

averaging filtermask sizes:nomask3x35x59x915x1535x35

Spatial Filtering apply a filter (also sometimes called a kernel or mask) to an image a new pixel value is calculated, one pixel at a time the neighbouring pixels influence the result. New Pixel Value the pixel at location (x, y) in the new image will have a value: