Dip - 05 Filtering
Dip - 05 Filtering
August 2023
Image transformations
As with any function, we can apply operators to an image
Source: S. Seitz
Take lots of images and
average them! What‟s the next
best thing?
@2023 Pham Van Huy and Trinh Hung Cuong 3
Image filtering
Modify the pixels in an image based on some function of a local
neighborhood of each pixel
Some
10 5 3 function
4 5 1 7
1 1 7
Source: L. Zhang
The prescription for the linear combination is called the “kernel” (or “mask”,
“filter”)
10 5 3 0 0 0
4 6 1 0 0.5 0 8
1 1 8 0 1 0.5
Source: L. Zhang
When the aperture is partially outside the image, the operation interpolates outlier
pixel values according to the specified border mode (refers [1] )
Refers [3] [4] more about template matching and normalized cross-correlation.
F H G
1 2 3 1 1 1 ? ? ?
9 9 9
4 5 6 1 1 1 ? 48 ?
9 9 9 9
8 9 10 1 1 1 ? ? ?
9 9 9
1 20 2 2 2 1 3 3 2 ? ? ? ? ? ?
1 2 3 3 2 1 2 2 2 ? ? ? ? ? ?
1 2 3 3 2 1 ? ? ? ? ? ?
1 2 2 2 2 1 ? ? ? ? ? ?
1 1 1 1 1 1 ? ? ? ? ? ?
https://www.geeksforgeeks.org/python-opencv-filter2d-function/
F H G
1 2 3 -1 0 1 ? ? ?
4 5 6 -2 0 2 ? ? ?
8 9 10 -1 0 1 ? ? ?
0 0 0
=
* 0
0
1
0
0
0
Source: D. Lowe
0 0 0
=
* 1
0
0
0
0
0
Source: D. Lowe
1 1 1
=
* 1
1
1
1
1
1
Source: D. Lowe
0 0 0 0 0 0 0 0 0 0 10 20 30 30 30 30 20 10
0 0 90 0 0 0 0 0 0 0 10 10 10 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
1 180 96 96 180 1 0 0 0 ? ? ? ? ? ?
1 180 96 96 180 1 ? ? ? ? ? ?
1 1 1 1 1 1 ? ? ? ? ? ?
1 180 96 96 180 1 0 0 0 ? ? ? ? ? ?
1 180 96 96 180 1 ? ? ? ? ? ?
1 1 1 1 1 1 ? ? ? ? ? ?
0 0 0 1 1 1
- =
* 0
0
2 0
0 0
1
1
1 1
1 1
Sharpening
Original
filter
(accentuates
Source: D. Lowe edges)
Source: D. Lowe
https://i.stack.imgur.com/XXBUN.png
20 120 20 20 120 20 0 -1 0 ? ? ? ? ? ?
20 120 20 20 120 20 ? ? ? ? ? ?
20 20 20 20 20 20 ? ? ? ? ? ?
Source: D. Forsyth
https://theailearner.com/2019/05/0
6/gaussian-blurring/
Source: C. Rasmussen
https://www.researchgate.net/figure/Discrete-approximation-of-the-Gaussian-kernels-
3x3-5x5-7x7_fig2_325768087
https://theailearner.com/tag/gaussian-filter/
Gaussian kernel weights(1-D) can be obtained quickly using the Pascal‟s Triangle
https://theailearner.com/tag/gaussian-filter/
@2023 Pham Van Huy and Trinh Hung Cuong 37
Gaussian blur – code
=1 =5 = 10 = 30
pixel pixels pixels pixels
– =
original smoothed (5x5) detail sharpened
Source: S. Lazebnik
+ = F+𝛼 𝐹−𝐻∗𝐹
α image blurred
original detail image
@2023 Pham Van Huy and Trinh Hung Cuong 40
Sharpen filter
unfiltered
filtered
= *
Source: Fergus, et al. “Removing Camera Shake from a Single Photograph”, SIGGRAPH 2006
Source: http://lullaby.homepage.dk/diy-
Bokeh: Blur out-of-focus regions of an image. camera/bokeh.html
https://www.researchgate.net/figure/Graphic-Depiction-of-Rank-Order-Filter-
Operation_fig6_268373873