Lect 6

Download as pdf or txt
Download as pdf or txt
You are on page 1of 34

Announcement

Homework #2 was posted online.


Homework #2 is due Tuesday, Sep. 13th before class starts.
Today’s Agenda

• Spatial filtering
• Linear filters
–Image Smoothing
–Image sharpening
Fundamentals of Spatial Filtering

• A neighborhood
• An operator with the same size: linear/nonlinear

Note: Each element in 𝑤 will


visit every pixel in the image
just once.

Linear spatial
a b
filtering:
g ( x, y ) =   w(s, t ) f ( x + s, y + t )
s = − at = − b

Inner product g ( x, y) = w • f = w f
T
Fundamentals of Spatial Filtering

Modifying the pixels in an image based on some function of a


local neighborhood of the pixels
p(x,y)
10 30 10
𝑔 𝑝
20 11 20 5.7

11 9 1
N(p)

g(p):
• Linear function
• Correlation
• Convolution
• Nonlinear function
• Order statistic (median)
Linear Filtering

0 0 0

* 0 1 0 =
0 0 0
Spatial Correlation: 1D Signal

 w(s) f ( x + s)
1D correlation
s =− a

2𝑎 2𝑎
Zero-padding: add zeros on the
left and right margin, respectively

• Full correlation result has the


size of 𝑀 + 2𝑎
• Cropped result has the size of 𝑀
– the size of the original signal
Spatial Correlation: 1D Signal

Discrete impulse
Flipped
a

 w(s) f ( x + s)
1D correlation
s =− a

• Full correlation result has the size


of 𝑀 + 2𝑎
• Cropped result has the size of 𝑀
– the size of the original signal

The impulse response is a rotation of the filter by 180 degree


Spatial Convolution: 1D Signal

Discrete impulse Flipped filter

a
1D convolution  w(s) f ( x − s)
s =− a

The impulse response is the same as the filter


Extend to 2D Image: 2D Image Correlation

a b

  w(s, t ) f ( x + s, y + t )
s = − at = − b

• Full correlation result has the size


of (𝑀 + 2𝑎, 𝑁 + 2𝑏)
• Cropped result has the size of
(𝑀, 𝑁) – the size of the original
The 2D impulse response of image
image correlation is a
rotation of the filter by 180
degree
Extend to 2D Image: 2D Image Convolution

a b

  w(s, t ) f ( x − s, y − t )
s = − at = − b

• Flip in both horizontal and vertical


directions (rotate 180 degree) ->
same if the filter is symmetric
• Convolution filter/mask/kernel
• Full convolution result has the size
of (𝑀 + 2𝑎, 𝑁 + 2𝑏)
The 2D impulse response of • Cropped result has the size of
image convolution is the (𝑀, 𝑁) – the size of the original
same as the filter image
Linear Filters

General process: Example: smoothing by


• Form new image whose averaging
pixels are a weighted sum • form the average of pixels in
of original pixel values, a neighborhood
using the same set of
weights at each point. Example: smoothing with a
Gaussian
Properties • form a weighted average of
• Output is a linear function of pixels in a neighborhood
the input
• Output is a shift-invariant Example: finding an edge
function of the input (i.e.
shift the input image two
pixels to the left, the output
is shifted two pixels to the
left)
Smoothing Spatial Filter – Low Pass Filters

Weighted average

a b

  w(s, t ) f ( x + s, y + t )
• Noise deduction
• reduction of “irrelevant details”
g ( x, y ) = s = − at = − b
a b
• edge blurred

  w(s, t )
s = − at = − b

Normalization factor
Smoothing Spatial Filter

9 1/9 1/9 1/9


1
Image averaging R =  zi 1/9 1/9 1/9
9 i =1 1/9 1/9 1/9

1 1 1
1 =
* 1 1 1
9
1 1 1
Smoothing Spatial Filter

x2 + y2
1 −
2D Gaussian filter h ( x, y ) = e 2 2
2 2

* =
Comparison using Different Smoothing
Filters – Different Kernels

Average Gaussian
Comparison using Different Smoothing
Filters: Different Size

Filter size: 3, 5, 9, 15, 35

Square size: 3, 5, 9, 15, 25, 35, 45, 55


with a spacing of 25

Bar: 5x100 with a spacing of 20

Letter size: 10, 12, 14, 16, 18, 20, 24


Image Smoothing and Thresholding
removed
Sharpening Spatial Filters

smooth sharpen
http://www.bythom.com/
sharpening.htm

Sharpening – highlight the transitions in intensity by differentiation

Smoothing – blur the transitions by summation


Sharpening Spatial Filters

Sharpening – highlight the transitions in intensity


by differentiation
• Electric printing
• Medical imaging
• Industrial inspection

Compared to smoothing – blur the transitions by


summation
Perceived Intensity is Not a Simple Function
of the Actual Intensity (1)

Enhance/amplify difference by
image sharpening
Sharpening Spatial Filters

Original image

𝑔 𝑥, 𝑦 = 𝑓 𝑥, 𝑦 + 𝑐 ∗ 𝑒(𝑥, 𝑦)

Sharpened image Magnifying factor Edge map

We will briefly introduce edge detection here and will have


a more comprehensive discussion when we discuss
image segmentation.
Spatial Filters for Edge Detection

f
= f ( x + 1) − f ( x)
x
Nonzero at
• onset of ramp and step
• along ramp

2 f Double edge
= f ( x + 1)
x 2

+ f ( x − 1) − 2 f ( x)
Thick edge
Nonzero at
• onset of ramp and step
• end of ramp and step
First-order VS Second-order Derivative for
Edge Detection

• First-order derivative produces thick edge along


the direction of transition
• Second-order derivative produces thinner edges
Gradient for Image Sharpening

Direction of change 𝜕𝑓
𝑔𝑥 𝜕𝑥
∇𝑓 = grad(𝑓) = 𝑔 =
𝑦 𝜕𝑓
𝜕𝑦
Magnitude of change (gradient image)
𝑀(𝑥, 𝑦) = 𝑚𝑎𝑔(∇𝑓)
http://en.wikipedia.org/wiki/Image_gradient
= 𝑔𝑥2 + 𝑔𝑦2
𝑀(𝑥, 𝑦) ≈ |𝑔𝑥 | + |𝑔𝑦 |
Gradient for Image Sharpening

Sum of the coefficients is 0 – the


response of a constant region is 0

Edge detectors:
• Roberts cross – fast
while sensitive to noise
• Sobel - smooth
Laplacian for Image Sharpening

2D Isotropic filters – rotation invariant


2 f 2 f
 f = 2 + 2
2

x y
Laplacian operator

 2
f  2
f  2
f
2 f = 2 + 2 + 2
x y xy

g ( x, y ) = f ( x, y )

+ c  2 f ( x, y ) 
Image sharpening with Laplacian
Image Sharpening

Scale the Laplacian by


shifting the intensity
range to [0, L-1]
Image Sharpening by Unsharp Masking and
Highboost Filtering

1. Blur the original


image
2. Subtract the blurred
image from the
original to get the
mask
3. Add the mask to the
original

g ( x, y) = f ( x, y) + k * ( f ( x, y) − f ( x, y) )
k 0

When k>1, it becomes a highboost filtering.


Original
An Example

Blurred

Unsharp mask

Unsharp masking k=1

Highboost filitering k=4.5


Gradient for Image Sharpening -- Example

Original Sobel gradient

An application in industrial defect detection.


Combining Spatial Enhancement Methods
Combining Spatial Enhancement Methods
Order-Statistic (Nonlinear) Filtering

Order-statistic filtering – rank the pixel values in the filter window and
assign the center pixel according to the property of the filter
• Median
• Min/max
Reading Assignments

Chapter 3.8 on using fuzzy techniques for intensity


transformation and spatial filtering
We are not going to cover it in the class

Next class, we will start Chapter 4: Filtering in the Frequency


Domain

You might also like