0% found this document useful (0 votes)
2 views

CV-5.1

The document discusses image filtering techniques, focusing on linear filtering, convolution, and correlation. It explains how linear filters operate by computing a weighted sum of neighboring pixels and highlights the properties of linear filters such as linearity and shift invariance. Additionally, it provides examples and visual illustrations of convolution and correlation processes in image processing.

Uploaded by

Thet Hsu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

CV-5.1

The document discusses image filtering techniques, focusing on linear filtering, convolution, and correlation. It explains how linear filters operate by computing a weighted sum of neighboring pixels and highlights the properties of linear filters such as linearity and shift invariance. Additionally, it provides examples and visual illustrations of convolution and correlation processes in image processing.

Uploaded by

Thet Hsu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 26

5.

Image Processing - II

1 Filtering Technique I
2 Filtering Technique II
3 OpenCV Practice
Dr. Thet Hsu Aung
Associate Professor

Faculty of Computer Science 1


Filtering Technique I

Ø Image Filtering

• Image filtering: for each pixel, compute function of local


neighborhood and output a new value.
• Image filtering is useful for many applications, including
smoothing, sharpening, removing noise, and edge detection, etc..

• Image filters can be classified as linear or nonlinear.


• Linear filters are also known as convolution filters as they can be
represented using a matrix multiplication.
• Thresholding and image equalization are examples of nonlinear
operations, as is the median filter.

2 Faculty of Computer Science


Filtering Technique I

Ø Linear Filtering

• Linear filtering is filtering in which the value of an output pixel is a


linear combination of the values of the pixels in the input pixel's
neighborhood.
• The linear filter works best with salt and pepper noise, and Gaussian
noise.
• Linear filter is the most common type, in which an output pixel’s value
(i.e. g(i, j)) is determined as a weighted sum of input pixel values (i.e.
f(i+k, j+l)).
� �, � = � � + �, � + � ℎ �, �
�,�

• 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)

4 Faculty of Computer Science


Filtering Technique I

Ø 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.

• To compute the output pixel – A(2,4)


1. Rotate the convolution kernel 180 degrees about its center element.
2. Slide the center element of the convolution kernel so that lies on top of the
(2,4) element of A.
3. Multiply each weight in the rotated convolution kernel by the pixel of A
underneath.
4. Sum up the individual products from step 3.

5 Faculty of Computer Science


Filtering Technique I

Ø Convolution Example

6 Faculty of Computer Science


Filtering Technique I

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

7 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
-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

Final output Image, g

13 Faculty of Computer Science


Filtering Technique I

Ø Correlation

– The filter “kernel” or “mask” is the prescription for the


weights in the linear combination.

1 2 (0,0)

H
3 4

Notation for F
correlation
operator (N,N)

14 Faculty of Computer Science


Filtering Technique I

Ø 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.

15 Faculty of Computer Science


Filtering Technique I

Ø Correlation Example

16 Faculty of Computer Science


Filtering Technique I

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

17 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 -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

19 Faculty of Computer Science


Filtering Technique I

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

20 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 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

21 Faculty of Computer Science


Filtering Technique I

Correlation

5 10 10 15

3 4 6 11

7 11 4 9

-5 4 4 5
Final output Image, g

22 Faculty of Computer Science


Filtering Technique I

Ø Key Properties of Linear Filters


• Linearity: filter(f1 + f2 ) = filter(f1) + filter(f2)

• Shift invariance: same behavior regardless of pixel location:


filter(shift(f)) = shift(filter(f))

• Any linear shift-invariant operator can be represented as a


convolution

23 Faculty of Computer Science


Filtering Technique I

• 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)

• Distributes over addition: a * (b + c) = (a * b) + (a * c)

• Scalars factor out: ka * b = a * kb = k (a * b)

• Identity: unit impulse e = [0, 0, 1, 0, 0], a * e = a

24 Faculty of Computer Science


Filtering Technique I

Ø Shift Invariant Linear System


• Shift invariant:
– Operator behaves the same everywhere, i.e. the value of the
output depends on the pattern in the image neighborhood, not
the position of the neighborhood.

• Linear:
– Superposition: h * (f1 + f2) = (h * f1) + (h * f2)
– Scaling: h * (kf) = k(h * f)

25 Faculty of Computer Science


Filtering Technique I

Ø Let's summarize:

– Linear filtering
– Convolution and Correlation
– Properties of linear filtering

26 Faculty of Computer Science

You might also like