Digital Image Processing Lecture 5: Neighborhood Processing: Spatial Filtering Prof. Charlene Tsai.
-
Upload
piers-barton -
Category
Documents
-
view
236 -
download
1
Transcript of Digital Image Processing Lecture 5: Neighborhood Processing: Spatial Filtering Prof. Charlene Tsai.
![Page 1: Digital Image Processing Lecture 5: Neighborhood Processing: Spatial Filtering Prof. Charlene Tsai.](https://reader035.fdocuments.in/reader035/viewer/2022062217/56649ef25503460f94c0446d/html5/thumbnails/1.jpg)
Digital Image ProcessingLecture 5: Neighborhood Processing: Spatial Filtering
Prof. Charlene Tsai
![Page 2: Digital Image Processing Lecture 5: Neighborhood Processing: Spatial Filtering Prof. Charlene Tsai.](https://reader035.fdocuments.in/reader035/viewer/2022062217/56649ef25503460f94c0446d/html5/thumbnails/2.jpg)
2
Spatial Filtering
Definition: a process that moves a subimage from point to point in an image, with the response at each image point predefined.
The subimage: filter, mask, kernel, template or window.
The values in a filter subimage are called coefficients, not pixels.
The process is also named convolution. Convolution of 2D function and is
denoted or wf * wf fg w
![Page 3: Digital Image Processing Lecture 5: Neighborhood Processing: Spatial Filtering Prof. Charlene Tsai.](https://reader035.fdocuments.in/reader035/viewer/2022062217/56649ef25503460f94c0446d/html5/thumbnails/3.jpg)
3
Illustration
W(-1,-1) W(-1,0) W(-1,1)
W(0,-1) W(0,0) W(0,1)
W(1,-1) W(1,0) W(1,1)
f(x-1,y-1) f(x-1,y) f(x-1,y+1)
f(x,y-1) f(x,y) f(x,y+1)
f(x+1,y-1) f(x+1,y) f(x+1,y+1)
x
yorigin
mask
Mask coefficients
Image section under mask
),(),(
),(
tysxftsw
yxga
as
b
bt
![Page 4: Digital Image Processing Lecture 5: Neighborhood Processing: Spatial Filtering Prof. Charlene Tsai.](https://reader035.fdocuments.in/reader035/viewer/2022062217/56649ef25503460f94c0446d/html5/thumbnails/4.jpg)
4
Example1: Averaging
One simple example is smoothing using a 3x3 mask.
f(x-1,y-1) f(x-1,y) f(x-1,y+1)
f(x,y-1) f(x,y) f(x,y+1)
f(x+1,y-1) f(x+1,y) f(x+1,y+1)
1/9 1/91/9
1/9 1/9 1/9
1/9 1/9 1/9
)1,1(...)1,1(),1()1,1(9
1),( yxfyxfyxfyxfyxg
![Page 5: Digital Image Processing Lecture 5: Neighborhood Processing: Spatial Filtering Prof. Charlene Tsai.](https://reader035.fdocuments.in/reader035/viewer/2022062217/56649ef25503460f94c0446d/html5/thumbnails/5.jpg)
5
Example2: Delta/Impulse Funciton An ideal impulse is defined using the Dirac
distribution
To visualize in 1D, picture a rectangular pulse from to with a height of . As , the width tends to 0 and the height tends to infinity as the total area remains constant at 1.
),( yx
0,0),( and ,1),(
yxyxdxdyyx
2x 2x 1 0
22
1
01
![Page 6: Digital Image Processing Lecture 5: Neighborhood Processing: Spatial Filtering Prof. Charlene Tsai.](https://reader035.fdocuments.in/reader035/viewer/2022062217/56649ef25503460f94c0446d/html5/thumbnails/6.jpg)
6
(cont)
Sifting property: It provides the value of f(x,y) at the point (a,b)
Delta function as the mask.
When moving across an image, it “copies” the value of image intensity.
),(),(),( bafdxdybyaxyxf
yxfdsdttstysxfyxg ,),(),(),(
![Page 7: Digital Image Processing Lecture 5: Neighborhood Processing: Spatial Filtering Prof. Charlene Tsai.](https://reader035.fdocuments.in/reader035/viewer/2022062217/56649ef25503460f94c0446d/html5/thumbnails/7.jpg)
7
General Formulation
2D Continuous space:
2D discrete space:
In digital image processing, we only deal with discrete space with a mask effective locally.
Convolution is commutative, associative and distributive.
dsdttswtysxfyxg ),(),(),(
s t
tswtysxfyxg ],[],[],[
Convolution kernel/mask
![Page 8: Digital Image Processing Lecture 5: Neighborhood Processing: Spatial Filtering Prof. Charlene Tsai.](https://reader035.fdocuments.in/reader035/viewer/2022062217/56649ef25503460f94c0446d/html5/thumbnails/8.jpg)
8
What happens at the borders? The mask falls outside the edge. Solutions?
Ignore the edges The resultant image is
smaller than the original Pad with zeros
Introducing unwanted artifacts
![Page 9: Digital Image Processing Lecture 5: Neighborhood Processing: Spatial Filtering Prof. Charlene Tsai.](https://reader035.fdocuments.in/reader035/viewer/2022062217/56649ef25503460f94c0446d/html5/thumbnails/9.jpg)
9
Values Outside the Range
Linear filtering might bring the intensity outside the display range.
Solutions? Clip values
Scaling transformation
Transform values in [gL,gH] to [0,255]
255 if
2550 if
0 if
255
0
x
x
x
xy
LH
L
gg
gxy
255
New min
New max
![Page 10: Digital Image Processing Lecture 5: Neighborhood Processing: Spatial Filtering Prof. Charlene Tsai.](https://reader035.fdocuments.in/reader035/viewer/2022062217/56649ef25503460f94c0446d/html5/thumbnails/10.jpg)
10
Separable Filters
Some filters can be implemented by successive application of two simpler filters.
Separability results in great time saving. By how much?
For a mask of size nxn, for each image pixel Originally, n2 multiplications and n2-1 additions After separation, 2n multiplications and 2n-2 additions
1113
1
1
1
1
3
1
111
111
111
9
1
![Page 11: Digital Image Processing Lecture 5: Neighborhood Processing: Spatial Filtering Prof. Charlene Tsai.](https://reader035.fdocuments.in/reader035/viewer/2022062217/56649ef25503460f94c0446d/html5/thumbnails/11.jpg)
11
Some terminology on Frequency… Frequencies: a measure of the amount by
which gray values change with distance. High/low-frequency components: large/small
changes in gray values over small distances. High/low-pass filter: passing high/low
components, and reducing or eliminating low/high-frequency filter.
![Page 12: Digital Image Processing Lecture 5: Neighborhood Processing: Spatial Filtering Prof. Charlene Tsai.](https://reader035.fdocuments.in/reader035/viewer/2022062217/56649ef25503460f94c0446d/html5/thumbnails/12.jpg)
12
Low-Pass Filter
Mostly for noise reduction/removal and smoothing 3x3 averaging filter to blur edges Gaussian filter,
based on Gaussian probability distribution function a popular filter for smoothing more later when we discuss image restoration
22 2xexP In 1D:
![Page 13: Digital Image Processing Lecture 5: Neighborhood Processing: Spatial Filtering Prof. Charlene Tsai.](https://reader035.fdocuments.in/reader035/viewer/2022062217/56649ef25503460f94c0446d/html5/thumbnails/13.jpg)
13
High-Pass Filter
The Laplacian, , is a high-pass filter,
Sum of coefficients is zero Insight: in areas where the gray values are
similar (low-frequency), application of the filter makes the gray values close to zero.
010
141
010
2h
yxf ,2
010
141
010
1h or
![Page 14: Digital Image Processing Lecture 5: Neighborhood Processing: Spatial Filtering Prof. Charlene Tsai.](https://reader035.fdocuments.in/reader035/viewer/2022062217/56649ef25503460f94c0446d/html5/thumbnails/14.jpg)
14
Laplacian Operator Laplacian is a derivative operator – 2nd
order derivative
Highlighting graylevel discontinuities. An edge detector isotropic in x- and y-direction.
),(2)1,()1,(
),(2),1(),1(
,
2
2
2
2
2
2
2
22
yxfyxfyxfy
f
yxfyxfyxfx
f
y
f
x
fyxf
010
141
010
1h
![Page 15: Digital Image Processing Lecture 5: Neighborhood Processing: Spatial Filtering Prof. Charlene Tsai.](https://reader035.fdocuments.in/reader035/viewer/2022062217/56649ef25503460f94c0446d/html5/thumbnails/15.jpg)
15
Laplacian Operator (con’d)
We may add the diagonal terms too => isotropic results for increments of
There are other variations/approximations:
111
181
111
4h
111
181
111
3hor
45
121
242
121
1hSeparable filter
![Page 16: Digital Image Processing Lecture 5: Neighborhood Processing: Spatial Filtering Prof. Charlene Tsai.](https://reader035.fdocuments.in/reader035/viewer/2022062217/56649ef25503460f94c0446d/html5/thumbnails/16.jpg)
16
Laplacian Filter: Demo
Original Laplacian-filtered
![Page 17: Digital Image Processing Lecture 5: Neighborhood Processing: Spatial Filtering Prof. Charlene Tsai.](https://reader035.fdocuments.in/reader035/viewer/2022062217/56649ef25503460f94c0446d/html5/thumbnails/17.jpg)
17
Laplacian: Application
Laplacian highlights discontinuities, and turn featureless regions into dark background.
How can we make good use of the property? One example is edge enhancement
original Laplacian enhanced
2
21
2
using ,,,
using ,,,,
hyxfyxf
hyxfyxfyxg
![Page 18: Digital Image Processing Lecture 5: Neighborhood Processing: Spatial Filtering Prof. Charlene Tsai.](https://reader035.fdocuments.in/reader035/viewer/2022062217/56649ef25503460f94c0446d/html5/thumbnails/18.jpg)
18
More Filters …
What feature does each mask highlight?
110
101
011
1h
111
000
111
2h
![Page 19: Digital Image Processing Lecture 5: Neighborhood Processing: Spatial Filtering Prof. Charlene Tsai.](https://reader035.fdocuments.in/reader035/viewer/2022062217/56649ef25503460f94c0446d/html5/thumbnails/19.jpg)
19
Edge Sharping
To make edges slightly sharper and crisper. This operation is referred to as edge
enhancement, edge crispening or unsharp masking.
A very popular practice in industry. Subtracting a blurred version of an image
from the image itself. yxfyxfyxf s ,,,
Sharpened image Blurred image
Original image
![Page 20: Digital Image Processing Lecture 5: Neighborhood Processing: Spatial Filtering Prof. Charlene Tsai.](https://reader035.fdocuments.in/reader035/viewer/2022062217/56649ef25503460f94c0446d/html5/thumbnails/20.jpg)
20
Unsharp Masking: Why it works
f(x,y) blurred image Sharpened
![Page 21: Digital Image Processing Lecture 5: Neighborhood Processing: Spatial Filtering Prof. Charlene Tsai.](https://reader035.fdocuments.in/reader035/viewer/2022062217/56649ef25503460f94c0446d/html5/thumbnails/21.jpg)
21
Filter for Unsharp Masking
Combining filtering and subtracting in one filter.
Schematically,
919191
919191
919191
000
010
000
919191
919191
9191911
000
010
000
AA
h
Original
Blur with low-pass
filter
Scale with A<1
Subtract
Scale for display
![Page 22: Digital Image Processing Lecture 5: Neighborhood Processing: Spatial Filtering Prof. Charlene Tsai.](https://reader035.fdocuments.in/reader035/viewer/2022062217/56649ef25503460f94c0446d/html5/thumbnails/22.jpg)
22
High-Boost Filtering
Generalization of unsharp masking
Here A is called boost coefficient, and We rewrite the equation as
Applicable to any sharpening operation can be The filter for fhb becomes
yxfyxAfyxfhb ,,, 1A
yxfyxfyxfAyxfhb ,,,1,
yxfyxfA s ,,1
sf ff 2
010
141
010
Ah
1A
![Page 23: Digital Image Processing Lecture 5: Neighborhood Processing: Spatial Filtering Prof. Charlene Tsai.](https://reader035.fdocuments.in/reader035/viewer/2022062217/56649ef25503460f94c0446d/html5/thumbnails/23.jpg)
23
High-Boost Filtering: Demo By varying A, better overall brightness can be
improved.
originalA=0
A=1A=1.7, much
brighter
010
141
010
Ah
![Page 24: Digital Image Processing Lecture 5: Neighborhood Processing: Spatial Filtering Prof. Charlene Tsai.](https://reader035.fdocuments.in/reader035/viewer/2022062217/56649ef25503460f94c0446d/html5/thumbnails/24.jpg)
24
Nonlinear Filters
Will discuss some of them in more detail later for the purpose of image restoration.
Maximum filter: the output the maximum value under the mask
Minimum filter: the output the minimum value under the mask
Rank-order filter: Elements under the mask are ordered, and a particular
value is returned. Both maximum and minimum filter are instances of rank-
order Another popular instance is median filter
![Page 25: Digital Image Processing Lecture 5: Neighborhood Processing: Spatial Filtering Prof. Charlene Tsai.](https://reader035.fdocuments.in/reader035/viewer/2022062217/56649ef25503460f94c0446d/html5/thumbnails/25.jpg)
25
More Nonlinear Filters
Alpha-trimmed mean filter: Order the values under the mask Trim off elements at either end of the ordered list Take the mean of the remainder E.g. assuming a 3x3 mask and the ordered list
Trimming of two elements at either end, the result of the filter is
9321 ... xxxx
576543 xxxxx
![Page 26: Digital Image Processing Lecture 5: Neighborhood Processing: Spatial Filtering Prof. Charlene Tsai.](https://reader035.fdocuments.in/reader035/viewer/2022062217/56649ef25503460f94c0446d/html5/thumbnails/26.jpg)
26
Summary
We introduced the concept of convolution We briefly discussed spatial filters of
Low-pass filter for smoothing High-pass filter for edge sharpening Nonlinear
We’ll come back to most of the filters under the appropriate topics.
![Page 27: Digital Image Processing Lecture 5: Neighborhood Processing: Spatial Filtering Prof. Charlene Tsai.](https://reader035.fdocuments.in/reader035/viewer/2022062217/56649ef25503460f94c0446d/html5/thumbnails/27.jpg)
27