CV-5.1
CV-5.1
Image Processing - II
1 Filtering Technique I
2 Filtering Technique II
3 OpenCV Practice
Dr. Thet Hsu Aung
Associate Professor
Ø Image Filtering
Ø Linear Filtering
• h(k, l) is called the kernel and different choices of h lead to filters that
smooth, sharpen, and detect edges, to name a few applications.
3 Faculty of Computer Science
Filtering Technique I
Ø Convolution
• Flip the filter in both dimensions (bottom to top, right to left)
• Then apply cross-correlation
4 3
(0,0)
H
2 1
Notation for
F
convolution
operator (N,N)
Ø Convolution
• Linear filtering of an image is accomplished through an operation
called convolution.
• In convolution, the value of an output pixel is computed as a weighted
sum of neighboring pixels.
• The matrix of weights is called the convolution kernel, also known as
the filter.
Ø Convolution Example
Convolution
Convolution kernel, ω Input Image, f
1 -1 -1 2 2 2 3
1 2 -1 2 1 3 3
1 1 1 2 2 1 2
1 3 2 2
Rotate 180o
1 1 1
-1 2 1
-1 -1 1
Convolution
1 1 1 2 2 2 3
-1 2 1 2 1 3 3
-1 -1 1 2 2 1 2
1 3 2 2
1 1 1
-1 42 2 2 3 5
Output
-1 2
-2 1 3 3
Image, g
Input 2 2 1 2
Image, f 1 3 2 2
8 Faculty of Computer Science
Filtering Technique I
Convolution
1 1 1 2 2 2 3
-1 2 1 2 1 3 3
-1 -1 1 2 2 1 2
1 3 2 2
1 1 1
2
-2 42 2 3 5 4
2
-2 1
-1 3 3 Output
Image, g
2 2 1 2
1 3 2 2
Input Image, f
9 Faculty of Computer Science
Filtering Technique I
Convolution
1 1 1 2 2 2 3
-1 2 1 2 1 3 3
-1 -1 1 2 2 1 2
1 3 2 2
1 1 1
2 2
-2 42 3 5 4 4
2 1 -3
-1 3 3 Output
Image, g
2 2 1 2
1 3 2 2
Input Image, f
10 Faculty of Computer Science
Filtering Technique I
Convolution
1 1 1 2 2 2 3
-1 2 1 2 1 3 3
-1 -1 1 2 2 1 2
1 3 2 2
1 1 1
2 2 2
-2 36 1 5 4 4 -2
2 1 3 -3
-3 3 1 Output
Image, g
2 2 1 2
1 3 2 2
Input Image, f
11 Faculty of Computer Science
Filtering Technique I
Convolution
1 1 1 2 2 2 3
-1 2 1 2 1 3 3
-1 -1 1 2 2 1 2
1 3 2 2
1 2 2 2 3 5 4 4 -2
Output
-1 42 1 3 3 9
Image, g
-1 -2
2 2 1 2
1 3 2 2
Input Image, f
12 Faculty of Computer Science
Filtering Technique I
Convolution
5 4 4 -2
9 6 14 5
11 7 6 5
9 12 8 5
Ø Correlation
1 2 (0,0)
H
3 4
Notation for F
correlation
operator (N,N)
Ø Correlation
• In correlation, the value of an output pixel is also computed as a
weighted sum of neighboring pixels.
• The difference is that the matrix of weights, in this case called
the correlation kernel, is not rotated during the computation.
• To compute the output pixel – A(2,4)
1. Slide the center element of the correlation kernel so that lies on
top of the (2,4) element of A.
2. Multiply each weight in the correlation kernel by the pixel of A
underneath.
3. Sum up the individual products from step 2.
Ø Correlation Example
Correlation
correlation kernel, ω
1 -1 -1
Input Image f
1 2 -1
2 2 2 3
1 1 1
2 1 3 3
Don’t rotate use it directly 2 2 1 2
1 3 2 2
Correlation
1 -1 -1 2 2 2 3
1 2 -1 2 1 3 3
1 1 1 2 2 1 2
1 -1 -1 1 3 2 2
1 42 2
-2 2 3 5
1 2 1 3 3 output
2 2 1 2 Image, g
1 3 2 2
Input Image, f
18 Faculty of Computer Science
Filtering Technique I
Correlation
1 -1 -1 2 2 2 3
1 2 -1 2 1 3 3
1 1 1 2 2 1 2
1 3 2 2
1 -1 -1
2 42 2
-2 3 5 10
2 1 3 3 output
2 2 1 2 Image, g
1 3 2 2
Input Image, f
1 -1 -1 Correlation 2 2 2 3
1 2 -1 2 1 3 3
1 1 1 2 2 1 2
1 3 2 2
1 -1 -1
2 2 42 3
-3 5 10 10
2 1 3 3 output
2 2 1 2 Image, g
1 3 2 2
Input Image, f
Correlation
1 -1 -1 2 2 2 3
1 2 -1 2 1 3 3
1 1 1 2 2 1 2
1 3 2 2
1 -1 -1
2 2 2 36 -1 5 10 10 15
2 1 3 3 1 output
2 2 1 2 Image, g
1 3 2 2
Input Image, f
Correlation
5 10 10 15
3 4 6 11
7 11 4 9
-5 4 4 5
Final output Image, g
• Commutative: a * b = b * a
– Conceptually no difference between filter and signal
• Associative: a * (b * c) = (a * b) * c
– Often apply several filters one after another: (((a * b1) * b2) * b3)
– This is equivalent to applying one filter: a * (b1 * b2 * b3)
• Linear:
– Superposition: h * (f1 + f2) = (h * f1) + (h * f2)
– Scaling: h * (kf) = k(h * f)
Ø Let's summarize:
– Linear filtering
– Convolution and Correlation
– Properties of linear filtering