![Page 1: Spatial Filtering and Convolution...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](https://reader033.vdocuments.site/reader033/viewer/2022053109/607b268e3d3af42ccc47268e/html5/thumbnails/1.jpg)
Spatial Filtering and Convolution
![Page 2: Spatial Filtering and Convolution...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](https://reader033.vdocuments.site/reader033/viewer/2022053109/607b268e3d3af42ccc47268e/html5/thumbnails/2.jpg)
Spatial Filtering
apply a filter (also sometimes called a kernel or mask) to an image
![Page 3: Spatial Filtering and Convolution...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](https://reader033.vdocuments.site/reader033/viewer/2022053109/607b268e3d3af42ccc47268e/html5/thumbnails/3.jpg)
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
![Page 4: Spatial Filtering and Convolution...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](https://reader033.vdocuments.site/reader033/viewer/2022053109/607b268e3d3af42ccc47268e/html5/thumbnails/4.jpg)
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
![Page 5: Spatial Filtering and Convolution...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](https://reader033.vdocuments.site/reader033/viewer/2022053109/607b268e3d3af42ccc47268e/html5/thumbnails/5.jpg)
![Page 6: Spatial Filtering and Convolution...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](https://reader033.vdocuments.site/reader033/viewer/2022053109/607b268e3d3af42ccc47268e/html5/thumbnails/6.jpg)
![Page 7: Spatial Filtering and Convolution...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](https://reader033.vdocuments.site/reader033/viewer/2022053109/607b268e3d3af42ccc47268e/html5/thumbnails/7.jpg)
New Pixel Value
the pixel at location (x, y) in the new image will have a value:
![Page 8: Spatial Filtering and Convolution...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](https://reader033.vdocuments.site/reader033/viewer/2022053109/607b268e3d3af42ccc47268e/html5/thumbnails/8.jpg)
New Pixel Value
the pixel at location (x, y) in the new image will have a 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)
![Page 9: Spatial Filtering and Convolution...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](https://reader033.vdocuments.site/reader033/viewer/2022053109/607b268e3d3af42ccc47268e/html5/thumbnails/9.jpg)
New Image
slide the mask over by one pixel and repeat
NOTE: original image requires a 1-pixel border be added or else the new image will be smaller than the original
![Page 10: Spatial Filtering and Convolution...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](https://reader033.vdocuments.site/reader033/viewer/2022053109/607b268e3d3af42ccc47268e/html5/thumbnails/10.jpg)
ExampleFind the new pixel value...
1 1 1
1 1 1
1 1 1
135 146 133 134 141
140 159 148 156 160
137 147 133 123 120
137 138 129 122 120
139 130 125 119 113
1/9
The mask
The original image
Multiply the values in the mask with the corresponding values in the image and add them together.
![Page 11: Spatial Filtering and Convolution...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](https://reader033.vdocuments.site/reader033/viewer/2022053109/607b268e3d3af42ccc47268e/html5/thumbnails/11.jpg)
ExampleFind the new pixel value...
1 1 1
1 1 1
1 1 1
135 146 133 134 141
140 159 148 156 160
137 147 133 123 120
137 138 129 122 120
139 130 125 119 113
1/9
The mask
The original imageNormalization factor. Equal to 1 over the sum of the elements in the mask.
Multiply the values in the mask with the corresponding values in the image and add them together.
![Page 12: Spatial Filtering and Convolution...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](https://reader033.vdocuments.site/reader033/viewer/2022053109/607b268e3d3af42ccc47268e/html5/thumbnails/12.jpg)
ExampleFind the new pixel value...
1 1 1
1 1 1
1 1 1
135 146 133 134 141
140 159 148 156 160
137 147 133 123 120
137 138 129 122 120
139 130 125 119 113
1/9
The mask
The original image
Multiply the values in the mask with the corresponding values in the image and add them together.
![Page 13: Spatial Filtering and Convolution...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](https://reader033.vdocuments.site/reader033/viewer/2022053109/607b268e3d3af42ccc47268e/html5/thumbnails/13.jpg)
ExampleFind the new pixel value...
1 1 1
1 1 1
1 1 1
135 146 133 134 141
140 159 148 156 160
137 147 133 123 120
137 138 129 122 120
139 130 125 119 113
1/9
The mask
The original image
Multiply the values in the mask with the corresponding values in the image and add them together.
![Page 14: Spatial Filtering and Convolution...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](https://reader033.vdocuments.site/reader033/viewer/2022053109/607b268e3d3af42ccc47268e/html5/thumbnails/14.jpg)
ExampleFind the new pixel value...
1 1 1
1 1 1
1 1 1
135 146 133 134 141
140 159 148 156 160
137 147 133 123 120
137 138 129 122 120
139 130 125 119 113
1/9
The mask
The original image
Multiply the values in the mask with the corresponding values in the image and add them together.
![Page 15: Spatial Filtering and Convolution...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](https://reader033.vdocuments.site/reader033/viewer/2022053109/607b268e3d3af42ccc47268e/html5/thumbnails/15.jpg)
ExampleFind the new pixel value...
1 1 1
1 1 1
1 1 1
135 146 133 134 141
140 159 148 156 160
137 147 133 123 120
137 138 129 122 120
139 130 125 119 113
1/9
The mask
The original image
Multiply the values in the mask with the corresponding values in the image and add them together.
![Page 16: Spatial Filtering and Convolution...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](https://reader033.vdocuments.site/reader033/viewer/2022053109/607b268e3d3af42ccc47268e/html5/thumbnails/16.jpg)
ExampleFind the new pixel value...
1 1 1
1 1 1
1 1 1
135 146 133 134 141
140 159 148 156 160
137 147 133 123 120
137 138 129 122 120
139 130 125 119 113
1/9
The mask
The original image
Multiply the values in the mask with the corresponding values in the image and add them together.
![Page 17: Spatial Filtering and Convolution...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](https://reader033.vdocuments.site/reader033/viewer/2022053109/607b268e3d3af42ccc47268e/html5/thumbnails/17.jpg)
ExampleFind the new pixel value...
1 1 1
1 1 1
1 1 1
135 146 133 134 141
140 159 148 156 160
137 147 133 123 120
137 138 129 122 120
139 130 125 119 113
1/9
The mask
The original image
Multiply the values in the mask with the corresponding values in the image and add them together.
![Page 18: Spatial Filtering and Convolution...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](https://reader033.vdocuments.site/reader033/viewer/2022053109/607b268e3d3af42ccc47268e/html5/thumbnails/18.jpg)
ExampleFind the new pixel value...
1 1 1
1 1 1
1 1 1
135 146 133 134 141
140 159 148 156 160
137 147 133 123 120
137 138 129 122 120
139 130 125 119 113
1/9
The mask
The original image
Multiply the values in the mask with the corresponding values in the image and add them together.
![Page 19: Spatial Filtering and Convolution...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](https://reader033.vdocuments.site/reader033/viewer/2022053109/607b268e3d3af42ccc47268e/html5/thumbnails/19.jpg)
ExampleFind the new pixel value...
1 1 1
1 1 1
1 1 1
135 146 133 134 141
140 159 148 156 160
137 147 133 123 120
137 138 129 122 120
139 130 125 119 113
1/9
The mask
The original image
Multiply the values in the mask with the corresponding values in the image and add them together.
![Page 20: Spatial Filtering and Convolution...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](https://reader033.vdocuments.site/reader033/viewer/2022053109/607b268e3d3af42ccc47268e/html5/thumbnails/20.jpg)
ExampleFind the new pixel value...
1 1 1
1 1 1
1 1 1
135 146 133 134 141
140 159 148 156 160
137 147 133 123 120
137 138 129 122 120
139 130 125 119 113
1/9
The mask
The original image
Multiply the values in the mask with the corresponding values in the image and add them together.
![Page 21: Spatial Filtering and Convolution...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](https://reader033.vdocuments.site/reader033/viewer/2022053109/607b268e3d3af42ccc47268e/html5/thumbnails/21.jpg)
Example
142 142 139
141 139 135
135 130 123
The result
![Page 22: Spatial Filtering and Convolution...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](https://reader033.vdocuments.site/reader033/viewer/2022053109/607b268e3d3af42ccc47268e/html5/thumbnails/22.jpg)
What did you just do?
1 1 1
1 1 1
1 1 1
1/9
![Page 23: Spatial Filtering and Convolution...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](https://reader033.vdocuments.site/reader033/viewer/2022053109/607b268e3d3af42ccc47268e/html5/thumbnails/23.jpg)
What did you just do?
this is the averaging mask!
1 1 1
1 1 1
1 1 1
1/9
![Page 24: Spatial Filtering and Convolution...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](https://reader033.vdocuments.site/reader033/viewer/2022053109/607b268e3d3af42ccc47268e/html5/thumbnails/24.jpg)
What did you just do?
this is the averaging mask!
the result is to smooth out the image
1 1 1
1 1 1
1 1 1
1/9
![Page 25: Spatial Filtering and Convolution...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](https://reader033.vdocuments.site/reader033/viewer/2022053109/607b268e3d3af42ccc47268e/html5/thumbnails/25.jpg)
Original image
![Page 26: Spatial Filtering and Convolution...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](https://reader033.vdocuments.site/reader033/viewer/2022053109/607b268e3d3af42ccc47268e/html5/thumbnails/26.jpg)
Averaged image
![Page 27: Spatial Filtering and Convolution...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](https://reader033.vdocuments.site/reader033/viewer/2022053109/607b268e3d3af42ccc47268e/html5/thumbnails/27.jpg)
![Page 28: Spatial Filtering and Convolution...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](https://reader033.vdocuments.site/reader033/viewer/2022053109/607b268e3d3af42ccc47268e/html5/thumbnails/28.jpg)
this operator is known as convolution
![Page 29: Spatial Filtering and Convolution...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](https://reader033.vdocuments.site/reader033/viewer/2022053109/607b268e3d3af42ccc47268e/html5/thumbnails/29.jpg)
this operator is known as convolution
one convolves an image with a filter
![Page 30: Spatial Filtering and Convolution...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](https://reader033.vdocuments.site/reader033/viewer/2022053109/607b268e3d3af42ccc47268e/html5/thumbnails/30.jpg)
More complicated filters
![Page 31: Spatial Filtering and Convolution...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](https://reader033.vdocuments.site/reader033/viewer/2022053109/607b268e3d3af42ccc47268e/html5/thumbnails/31.jpg)
Gaussian Filter
![Page 32: Spatial Filtering and Convolution...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](https://reader033.vdocuments.site/reader033/viewer/2022053109/607b268e3d3af42ccc47268e/html5/thumbnails/32.jpg)
Gaussian Filter
![Page 33: Spatial Filtering and Convolution...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](https://reader033.vdocuments.site/reader033/viewer/2022053109/607b268e3d3af42ccc47268e/html5/thumbnails/33.jpg)
What would a Gaussian function look like expressed as a 3x3 mask?
![Page 34: Spatial Filtering and Convolution...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](https://reader033.vdocuments.site/reader033/viewer/2022053109/607b268e3d3af42ccc47268e/html5/thumbnails/34.jpg)
3x3 Gaussian
a Gaussian function expressed as a 3x3 mask
![Page 35: Spatial Filtering and Convolution...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](https://reader033.vdocuments.site/reader033/viewer/2022053109/607b268e3d3af42ccc47268e/html5/thumbnails/35.jpg)
3x3 Gaussian
1 2 1
2 4 2
1 2 1
1/16a Gaussian function expressed as a 3x3 mask
![Page 36: Spatial Filtering and Convolution...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](https://reader033.vdocuments.site/reader033/viewer/2022053109/607b268e3d3af42ccc47268e/html5/thumbnails/36.jpg)
Not all masks are 3x3
![Page 37: Spatial Filtering and Convolution...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](https://reader033.vdocuments.site/reader033/viewer/2022053109/607b268e3d3af42ccc47268e/html5/thumbnails/37.jpg)
0.01 0.03 0.05 0.08 0.1 0.11 0.1 0.08 0.05 0.03 0.01
0.03 0.06 0.11 0.18 0.23 0.25 0.23 0.18 0.11 0.06 0.03
0.05 0.11 0.21 0.32 0.42 0.46 0.42 0.32 0.21 0.11 0.05
0.08 0.18 0.32 0.5 0.65 0.71 0.65 0.5 0.32 0.18 0.08
0.1 0.23 0.42 0.65 0.84 0.92 0.84 0.65 0.42 0.23 0.1
0.11 0.25 0.46 0.71 0.92 1 0.92 0.71 0.46 0.25 0.11
0.1 0.23 0.42 0.65 0.84 0.92 0.84 0.65 0.42 0.23 0.1
0.08 0.18 0.32 0.5 0.65 0.71 0.65 0.5 0.32 0.18 0.08
0.05 0.11 0.21 0.32 0.42 0.46 0.42 0.32 0.21 0.11 0.05
0.03 0.06 0.11 0.18 0.23 0.25 0.23 0.18 0.11 0.06 0.03
0.01 0.03 0.05 0.08 0.1 0.11 0.1 0.08 0.05 0.03 0.01
![Page 38: Spatial Filtering and Convolution...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](https://reader033.vdocuments.site/reader033/viewer/2022053109/607b268e3d3af42ccc47268e/html5/thumbnails/38.jpg)
0.01 0.03 0.05 0.08 0.1 0.11 0.1 0.08 0.05 0.03 0.01
0.03 0.06 0.11 0.18 0.23 0.25 0.23 0.18 0.11 0.06 0.03
0.05 0.11 0.21 0.32 0.42 0.46 0.42 0.32 0.21 0.11 0.05
0.08 0.18 0.32 0.5 0.65 0.71 0.65 0.5 0.32 0.18 0.08
0.1 0.23 0.42 0.65 0.84 0.92 0.84 0.65 0.42 0.23 0.1
0.11 0.25 0.46 0.71 0.92 1 0.92 0.71 0.46 0.25 0.11
0.1 0.23 0.42 0.65 0.84 0.92 0.84 0.65 0.42 0.23 0.1
0.08 0.18 0.32 0.5 0.65 0.71 0.65 0.5 0.32 0.18 0.08
0.05 0.11 0.21 0.32 0.42 0.46 0.42 0.32 0.21 0.11 0.05
0.03 0.06 0.11 0.18 0.23 0.25 0.23 0.18 0.11 0.06 0.03
0.01 0.03 0.05 0.08 0.1 0.11 0.1 0.08 0.05 0.03 0.01
11 x 11 mask
![Page 39: Spatial Filtering and Convolution...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](https://reader033.vdocuments.site/reader033/viewer/2022053109/607b268e3d3af42ccc47268e/html5/thumbnails/39.jpg)
the larger the mask, the greater the effect
Mask Sizes
![Page 40: Spatial Filtering and Convolution...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](https://reader033.vdocuments.site/reader033/viewer/2022053109/607b268e3d3af42ccc47268e/html5/thumbnails/40.jpg)
averaging filter
mask sizes:
no mask 3x3
5x5 9x9
15x15 35x35