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

Image Filtering: Associate Professor Faculty of Computer Science Institute of Business Administration - Karachi

The document discusses image filtering techniques. It introduces point operations and arithmetic operations that can be used for image filtering. Common filters include smoothing filters using averaging, and linear filtering using a convolution with a filter kernel. The effects of filters can include denoising, sharpening, and modifying intensities or contrast in an image.

Uploaded by

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

Image Filtering: Associate Professor Faculty of Computer Science Institute of Business Administration - Karachi

The document discusses image filtering techniques. It introduces point operations and arithmetic operations that can be used for image filtering. Common filters include smoothing filters using averaging, and linear filtering using a convolution with a filter kernel. The effects of filters can include denoising, sharpening, and modifying intensities or contrast in an image.

Uploaded by

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

Image Filtering

Imran N. Junejo
Associate Professor
Faculty of Computer Science
Institute of Business Administration - Karachi

1
Lecture outline
• point-operations
• Learn about image filtering

2
Point Operations
• Point transformation: changes a pixel’s value without changing its
location.

In this case f is referred to as a grey level transformation function or a point


processing operation
3
Point Operations
• Point transformation: changes a pixel’s value without changing its
location.
• Can be applied by: Arithmetic Operations
Arithmetic Operations

• A useful class of gray level transformations is the set of arithmetic


operations, depicted in graphical form in the following figure:

5
Arithmetic Operations

Overflow issue?

6
Arithmetic Operations
What if b is negative?

If b is negative, the image will darken

7
Analytic Transformations
• Graylevel transformations can be specified using analytic functions such
as the logarithm, exponential, or power functions:

8
Logarithmic Transformations can be used to brighten the intensities of an
image (like the Gamma Transformation, where gamma < 1). More often, it is
used to increase the detail (or contrast) of lower intensity values.

9
Point Operations
• Point transformation: changes a pixel’s value without changing its
location.
• Can be applied by: Thresholding
Intensity Transformations
Point Operations
• Point transformation: changes a pixel’s value without changing its
location.
• Can be applied by: Histogram Modifications
What is a Filter
• Point operations are limited (why)
• They cannot accomplish tasks like sharpening
or smoothing

13
Noise Filtering or Image Filtering
• Given a corrupted image I by noise n,
attenuate, if possible eliminate n, without
altering I significantly.

14
Image filtering
• Filtering refers to linear transforms that change the
frequency contents of signals.
• Transformations where each output pixel is a
function of the input pixel and its neighbors.
• Really important!
– Enhance images
• Denoise, resize, increase contrast, etc.
– Extract information from images
• Texture, edges, distinctive points, etc.
– Detect patterns
• Template matching
15
Image filtering
• Filtering refers to linear transforms that change the
frequency contents of signals (def: signal processing).
• Transformations where each output pixel is a
function of the input pixel and its neighbors.
• Really important!
– Enhance images
• Denoise, resize, increase contrast, etc.
– Extract information from images
• Texture, edges, distinctive points, etc.
– Detect patterns
• Template matching
16
Smoothing an image by
averaging
• Replace each pixel by the average of its neighboring pixels
• Assume a 3x3 neighborhood:

P0 P1 P2
P3 P4 P5
P6 P7 P8

17
P0 P1 P2
P3 P4 P5
P6 P7 P8

18
Averaging filter

19
G

• In general a filter applies a function over the values of a


small neighborhood of pixels to compute the result
• The size of the filter = the size of the neighborhood: 3x3,
5x5, 7x7, …, 21x21,..
• The shape of the filter region is not necessarily square,
can be a rectangle, a circle…
• Filters can be linear or nonlinear
20
Linear Filtering
• The output is the linear combination of the
neighborhood pixels
h[ m, n]   g[ k , l ] f [ m  k , n  l ]
k ,l

1 3 0 1 0 -1
2 10 2 1 0.1 -1 = 5
4 1 1 1 0 -1
Image filter Filter Output
21
Image filtering 1 1 1

g[ , ] 1 1 1

1 1 1

f [.,.] h[.,.]
0 0 0 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0 0 0 0

0 0 0 90 90 90 90 90 0 0

0 0 0 90 90 90 90 90 0 0

0 0 0 90 90 90 90 90 0 0

0
0 0
0 0
0 90
90 0
0 90
90 90
90 90
90 0
0 0
0

0
0 0
0 0
0 90
90 90
90 90
90 90
90 90
90 0
0 0
0

0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0

0
0 0
0 90
90 0
0 0
0 0
0 0
0 0
0 0
0 0
0

0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0

h[ m, n]   g[ k , l ] f [ m  k , n  l ]
22
k ,l Credit: S. Seitz
Image filtering 1 1 1

g[ , ] 1 1 1

1 1 1

f [.,.] h[.,.]
0 0 0 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0 0 0 0 10

0 0 0 90 90 90 90 90 0 0

0 0 0 90 90 90 90 90 0 0

0 0 0 90 90 90 90 90 0 0

0 0 0 90 0 90 90 90 0 0

0 0 0 90 90 90 90 90 0 0

0 0 0 0 0 0 0 0 0 0

0 0 90 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0 0 0

h[ m, n]   g[ k , l ] f [ m  k , n  l ]
23
k ,l Credit: S. Seitz
Image filtering 1 1 1

g[ , ] 1 1 1

1 1 1

f [.,.] h[.,.]
0 0 0 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0 0 0 0 10 20

0 0 0 90 90 90 90 90 0 0

0 0 0 90 90 90 90 90 0 0

0 0 0 90 90 90 90 90 0 0

0 0 0 90 0 90 90 90 0 0

0 0 0 90 90 90 90 90 0 0

0 0 0 0 0 0 0 0 0 0

0 0 90 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0 0 0

h[ m, n]   g[ k , l ] f [ m  k , n  l ]
24
k ,l Credit: S. Seitz
Image filtering 1 1 1

g[ , ] 1 1 1

1 1 1

f [.,.] h[.,.]
0 0 0 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0 0 0 0 10 20 30

0 0 0 90 90 90 90 90 0 0

0 0 0 90 90 90 90 90 0 0

0 0 0 90 90 90 90 90 0 0

0 0 0 90 0 90 90 90 0 0

0 0 0 90 90 90 90 90 0 0

0 0 0 0 0 0 0 0 0 0

0 0 90 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0 0 0

h[ m, n]   g[ k , l ] f [ m  k , n  l ]
25
k ,l Credit: S. Seitz
Image filtering 1 1 1

g[ , ] 1 1 1

1 1 1

f [.,.] h[.,.]
0 0 0 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0 0 0 0 10 20 30 30

0 0 0 90 90 90 90 90 0 0

0 0 0 90 90 90 90 90 0 0

0 0 0 90 90 90 90 90 0 0

0 0 0 90 0 90 90 90 0 0

0 0 0 90 90 90 90 90 0 0

0 0 0 0 0 0 0 0 0 0

0 0 90 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0 0 0

h[ m, n]   g[ k , l ] f [ m  k , n  l ]
26
k ,l Credit: S. Seitz
Image filtering 1 1 1

g[ , ] 1 1 1

1 1 1

f [.,.] h[.,.]
0 0 0 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0 0 0 0 10 20 30 30

0 0 0 90 90 90 90 90 0 0

0 0 0 90 90 90 90 90 0 0

0 0 0 90 90 90 90 90 0 0

0 0 0 90 0 90 90 90 0 0

0 0 0 90 90 90 90 90 0 0
?
0 0 0 0 0 0 0 0 0 0

0 0 90 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0 0 0

h[ m, n]   g[ k , l ] f [ m  k , n  l ]
27
k ,l Credit: S. Seitz
Image filtering 1 1 1

g[ , ] 1 1 1

1 1 1

f [.,.] h[.,.]
0 0 0 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0 0 0 0 10 20 30 30

0 0 0 90 90 90 90 90 0 0

0 0 0 90 90 90 90 90 0 0

0 0 0 90 90 90 90 90 0 0
?
0 0 0 90 0 90 90 90 0 0

0 0 0 90 90 90 90 90 0 0 50

0 0 0 0 0 0 0 0 0 0

0 0 90 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0 0 0

h[ m, n]   g[ k , l ] f [ m  k , n  l ]
28
k ,l Credit: S. Seitz
Image filtering g[ , ] 1 1 1
1 1 1
1 1 1

f [.,.] h[.,.]
0 0 0 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0 0 0 0 10 20 30 30 30 20 10

0 0 0 90 90 90 90 90 0 0 0 20 40 60 60 60 40 20

0 0 0 90 90 90 90 90 0 0 0 30 60 90 90 90 60 30

0 0 0 90 90 90 90 90 0 0 0 30 50 80 80 90 60 30

0 0 0 90 0 90 90 90 0 0 0 30 50 80 80 90 60 30

0 0 0 90 90 90 90 90 0 0 0 20 30 50 50 60 40 20

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

h[ m, n]   g[ k , l ] f [ m  k , n  l ]
29
k ,l Credit: S. Seitz
g

f'

30
Box Filter

g[ , ]
What does it do?
• Replaces each pixel with 1 1 1
an average of its
neighborhood 1 1 1

1 1 1
• Achieve smoothing effect
(remove sharp features)

31
Slide credit: David Lowe (UBC)
Smoothing with box filter

32
Practice with linear filters

?
0 0 0
0 1 0
0 0 0

Original

33
Source: D. Lowe
Practice with linear filters

0 0 0
0 1 0
0 0 0

Original Filtered
(no change)

34
Source: D. Lowe
Practice with linear filters

?
0 0 0
0 0 1
0 0 0

Original

35
Source: D. Lowe
Practice with linear filters

0 0 0
0 0 1
0 0 0

Original Shifted left


By 1 pixel

36
Source: D. Lowe
Practice with linear filters

-
0 0 0 1 1 1
0
0
2
0
0
0
1
1
1
1
1
1
?
(Note that filter sums to 1)
Original

37
Source: D. Lowe
Practice with linear filters

-
0 0 0 1 1 1
0 2 0 1 1 1
0 0 0 1 1 1

Original Sharpening filter


- Accentuates differences with local
average

38
Source: D. Lowe
Sharpening

39
Source: D. Lowe
Other filters

1 0 -1
2 0 -2
1 0 -1
Sobel

Vertical Edge
(absolute value) 40
Other filters

1 2 1
0 0 0
-1 -2 -1
Sobel

Horizontal Edge
(absolute value) 41
Convolution
[filtering in frequency domain]

f i, j   I * H   I k , l H i  k , j  l 
k l
H
I  Image
X  flip
H7 H8 H9 H1 H2 H3
H  Kernel H4 H5 H6 H4 H5 H6
H1 H2 H3 H7 H8 H9

I Y  flip
I1 I2 I3 H9 H8 H7 I * H  I1 H 9  I 2 H 8  I 3 H 7
I4 I5 I6  H6 H5 H4  I 4 H 6  I5 H5  I6 H 4
I7 I8 I9 H3 H2 H1  I 7 H 3  I 8 H 2  I 9 H1
42
Gaussian Filter
Special type of smoothing kernel

G x, y  
1  x2  y2
exp  
 
2 2
 2 
 2 

H i, j  
1
exp  

 i  k  12   j  k  12 
2 2
 2 
 2 

where H i, j  is 2k  1 2k  1 array

43
1-D Gaussian Filter

 x2

g ( x)  e 2 2

g ( x)  .011 .13 .6 1 .6 .13 .011

44
Smoothing with Gaussian filter

45
Smoothing with box filter

46
Gaussian filters
• Remove “high-frequency” components from the
image (low-pass filter)
– Images become more smooth
• Convolution with self is another Gaussian
– So can smooth with small-width kernel, repeat, and
get same result as larger-width kernel would have
– Convolving two times with Gaussian kernel of width σ
is same as convolving once with kernel of width σ√2
• Separable kernel
– Factors into product of two 1D Gaussians

47
Source: K. Grauman
Separability example
2D convolution
(center location only)

The filter factors


into a product of 1D
filters:

Perform convolution =
along rows: *

Followed by convolution =
along the remaining column: *
48
Source: K. Grauman
Properties of Gaussian
• Most common natural model
• Smooth function, it has infinite number of
derivatives
• Fourier Transform of Gaussian is Gaussian.
• Convolution of a Gaussian with itself is a
Gaussian.
• Gaussian kernels is separable.

49
Linear filtering and convolution

Original Noisy

Filtered
Filtered
σ=3.0
σ=1.5
50
Gaussian filters

= 1 pixel = 5 pixels = 10 pixels = 30 pixels

51
Types of Linear Filters

52
Practical matters
• What about near the edge?
– the filter window falls off the edge of the image
– need to extrapolate
– methods:
• clip filter (black)
• wrap around
• copy edge
• reflect across edge

53
Source: S. Marschner
Examples
• I2 = cv2.blur(I,(5,5))
• I2 = cv2.blur(I,(15,15))
• I2 = cv2.blur(I,(50,50))

cv2.GaussianBlur(I, (3,3),1.5)

Based on A Practical Introduction to Computer Vision with OpenCV 2 by


Images Slide 54
Kenneth Dawson-Howe © Wiley & Sons Inc. 2014
Smoothing – Examples

Based on A Practical Introduction to Computer Vision with OpenCV by


Images Slide 55
Kenneth Dawson-Howe © Wiley & Sons Inc. 2014
Smoothing – Median Filter (non-linear)
• Use the median value… 11 18 20 21 23 25 25 30 250
Median = 23 Average = 47
• Not affected by noise
• Doesn’t blur edges much
• Can be applied iteratively
• Damages thin lines and sharp corners
– Change region shape

• Computational expensive
– Standard – O(r2log r)
– Huang – O(r)
– Perreault (2007) – O(1)
medianBlur(image, smoothed_image, 5);

Based on A Practical Introduction to Computer Vision with OpenCV by


Images Slide 56
Kenneth Dawson-Howe © Wiley & Sons Inc. 2014
Smoothing – Examples

noisy 3x3 smoothing Gaussian Median

Based on A Practical Introduction to Computer Vision with OpenCV by


Images Slide 57
Kenneth Dawson-Howe © Wiley & Sons Inc. 2014
Take-home messages
• Linear filtering is sum of dot
1 1 1
product at each position 1 1 1

– Can smooth, sharpen, translate 1 1 1

(among many other uses)

• Be aware of details for filter size,


extrapolation, cropping

58
Suggested Reading

• Chapter 3, Emanuele Trucco, Alessandro


Verri, "Introductory Techniques for 3-D
Computer Vision”
• Chapter 7,8, David A. Forsyth and Jean
Ponce, "Computer Vision: A Modern
Approach“

59

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy