Spatial image filtering - cse.sc.educse.sc.edu/~tongy/csce763/lectures/lect7.pdfToday’s Agenda •...

31
Today’s Agenda Spatial image filtering • Linear filters –Image Smoothing –Image sharpening

Transcript of Spatial image filtering - cse.sc.educse.sc.edu/~tongy/csce763/lectures/lect7.pdfToday’s Agenda •...

Page 1: Spatial image filtering - cse.sc.educse.sc.edu/~tongy/csce763/lectures/lect7.pdfToday’s Agenda • Spatial image filtering •Linear filters –Image Smoothing –Image sharpening

Today’s Agenda

• Spatial image filtering • Linear filters

–Image Smoothing –Image sharpening

Page 2: Spatial image filtering - cse.sc.educse.sc.edu/~tongy/csce763/lectures/lect7.pdfToday’s Agenda • Spatial image filtering •Linear filters –Image Smoothing –Image sharpening

Fundamentals of Spatial Filtering

∑∑−= −=

++=a

as

b

bttysxftswyxg ),(),(),(

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

Inner product fwfw Tyxg =•=),(

Linear spatial filtering:

Note: Each element in 𝑤 will visit every pixel in the image just once.

Page 3: Spatial image filtering - cse.sc.educse.sc.edu/~tongy/csce763/lectures/lect7.pdfToday’s Agenda • Spatial image filtering •Linear filters –Image Smoothing –Image sharpening

Fundamentals of Spatial Filtering

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

10 30 10

20 11 20

11 9 1

p(x,y)

N(p)

5.7

g(p): • Linear function

• Correlation • Convolution

• Nonlinear function • Order statistic (median)

𝑔 𝑝

Page 4: Spatial image filtering - cse.sc.educse.sc.edu/~tongy/csce763/lectures/lect7.pdfToday’s Agenda • Spatial image filtering •Linear filters –Image Smoothing –Image sharpening

Spatial Correlation: 1D Signal

∑−=

+a

assxfsw )()(1D correlation

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

2𝑎 2𝑎

• Full correlation result has the size of 𝑀 + 2𝑎

• Cropped result has the size of 𝑀 – the size of the original signal

Page 5: Spatial image filtering - cse.sc.educse.sc.edu/~tongy/csce763/lectures/lect7.pdfToday’s Agenda • Spatial image filtering •Linear filters –Image Smoothing –Image sharpening

Spatial Correlation: 1D Signal

Flipped

Discrete impulse

∑−=

+a

assxfsw )()(1D correlation

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

• Full correlation result has the size of 𝑀 + 2𝑎

• Cropped result has the size of 𝑀 – the size of the original signal

Page 6: Spatial image filtering - cse.sc.educse.sc.edu/~tongy/csce763/lectures/lect7.pdfToday’s Agenda • Spatial image filtering •Linear filters –Image Smoothing –Image sharpening

Spatial Convolution: 1D Signal

Flipped filter Discrete impulse

∑−=

−a

assxfsw )()(1D convolution

The impulse response is the same as the filter

Page 7: Spatial image filtering - cse.sc.educse.sc.edu/~tongy/csce763/lectures/lect7.pdfToday’s Agenda • Spatial image filtering •Linear filters –Image Smoothing –Image sharpening

Extend to 2D Image: 2D Image Correlation

∑∑−= −=

++a

as

b

bttysxftsw ),(),(

• Full correlation result has the size of (𝑀 + 2𝑎,𝑁 + 2𝑏)

• Cropped result has the size of (𝑀,𝑁) – the size of the original image The 2D impulse response of

image correlation is a rotation of the filter by 180 degree

Page 8: Spatial image filtering - cse.sc.educse.sc.edu/~tongy/csce763/lectures/lect7.pdfToday’s Agenda • Spatial image filtering •Linear filters –Image Smoothing –Image sharpening

Extend to 2D Image: 2D Image Convolution

∑∑−= −=

−−a

as

b

bttysxftsw ),(),(

• 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𝑏) • Cropped result has the size of (𝑀,𝑁) – the size of the original image

The 2D impulse response of image convolution is the same as the filter

Page 9: Spatial image filtering - cse.sc.educse.sc.edu/~tongy/csce763/lectures/lect7.pdfToday’s Agenda • Spatial image filtering •Linear filters –Image Smoothing –Image sharpening

Linear Filters

General process: • Form new image whose

pixels are a weighted sum of original pixel values, using the same set of weights at each point.

Properties • Output is a linear function of

the input • Output is a shift-invariant

function of the input (i.e. shift the input image two pixels to the left, the output is shifted two pixels to the left)

Example: smoothing by averaging • form the average of pixels in

a neighborhood

Example: smoothing with a Gaussian • form a weighted average of

pixels in a neighborhood

Example: finding an edge

Page 10: Spatial image filtering - cse.sc.educse.sc.edu/~tongy/csce763/lectures/lect7.pdfToday’s Agenda • Spatial image filtering •Linear filters –Image Smoothing –Image sharpening

Smoothing Spatial Filter – Low Pass Filters

∑∑

∑∑

−= −=

−= −=

++= a

as

b

bt

a

as

b

bt

tsw

tysxftswyxg

),(

),(),(),(

Normalization factor

• Noise deduction • reduction of “irrelevant details” • edge blurred

Weighted average

Page 11: Spatial image filtering - cse.sc.educse.sc.edu/~tongy/csce763/lectures/lect7.pdfToday’s Agenda • Spatial image filtering •Linear filters –Image Smoothing –Image sharpening

Smoothing Spatial Filter

∑=

=9

191

iizRImage averaging

1/9 1/9 1/9 1/9 1/9 1/9 1/9 1/9 1/9

1 1 1

1 1 1

1 1 1 91* =

Page 12: Spatial image filtering - cse.sc.educse.sc.edu/~tongy/csce763/lectures/lect7.pdfToday’s Agenda • Spatial image filtering •Linear filters –Image Smoothing –Image sharpening

Smoothing Spatial Filter

2

22

222

1),( σ

πσ

yx

eyxh+

−=2D Gaussian filter

* =

Page 13: Spatial image filtering - cse.sc.educse.sc.edu/~tongy/csce763/lectures/lect7.pdfToday’s Agenda • Spatial image filtering •Linear filters –Image Smoothing –Image sharpening

Comparison using Different Smoothing Filters – Different Kernels

Average Gaussian

Page 14: Spatial image filtering - cse.sc.educse.sc.edu/~tongy/csce763/lectures/lect7.pdfToday’s Agenda • Spatial image filtering •Linear filters –Image Smoothing –Image sharpening

Comparison using Different Smoothing Filters: Different Size

Page 15: Spatial image filtering - cse.sc.educse.sc.edu/~tongy/csce763/lectures/lect7.pdfToday’s Agenda • Spatial image filtering •Linear filters –Image Smoothing –Image sharpening

Image Smoothing and Thresholding removed

Page 16: Spatial image filtering - cse.sc.educse.sc.edu/~tongy/csce763/lectures/lect7.pdfToday’s Agenda • Spatial image filtering •Linear filters –Image Smoothing –Image sharpening

Sharpening Spatial Filters

Sharpening – highlight the transitions in intensity by differentiation Smoothing – blur the transitions by summation

smooth sharpen

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

Page 17: Spatial image filtering - cse.sc.educse.sc.edu/~tongy/csce763/lectures/lect7.pdfToday’s Agenda • Spatial image filtering •Linear filters –Image Smoothing –Image sharpening

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

Page 18: Spatial image filtering - cse.sc.educse.sc.edu/~tongy/csce763/lectures/lect7.pdfToday’s Agenda • Spatial image filtering •Linear filters –Image Smoothing –Image sharpening

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

Enhance/amplify difference by image sharpening

Page 19: Spatial image filtering - cse.sc.educse.sc.edu/~tongy/csce763/lectures/lect7.pdfToday’s Agenda • Spatial image filtering •Linear filters –Image Smoothing –Image sharpening

Sharpening Spatial Filters

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

Sharpened image

Original image

Magnifying factor Edge map

Page 20: Spatial image filtering - cse.sc.educse.sc.edu/~tongy/csce763/lectures/lect7.pdfToday’s Agenda • Spatial image filtering •Linear filters –Image Smoothing –Image sharpening

Spatial Filters for Edge Detection

)()1( xfxfxf

−+=∂∂

)(2)1(

)1(2

2

xfxf

xfx

f

−−+

+=∂∂

Nonzero at • onset of ramp and step • along ramp or step

Nonzero at • onset of ramp and step • end of ramp and step

Thick edge

Double edge

Page 21: Spatial image filtering - cse.sc.educse.sc.edu/~tongy/csce763/lectures/lect7.pdfToday’s Agenda • Spatial image filtering •Linear filters –Image Smoothing –Image sharpening

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

Page 22: Spatial image filtering - cse.sc.educse.sc.edu/~tongy/csce763/lectures/lect7.pdfToday’s Agenda • Spatial image filtering •Linear filters –Image Smoothing –Image sharpening

Gradient for Image Sharpening

||||),(

)(),(

)(grad

22

yx

yx

y

x

ggyxM

ggfmagyxM

xf

xf

gg

ff

+≈

+=∇=

∂∂

∂∂

=

==∇

Direction of change

Magnitude of change (gradient image)

http://en.wikipedia.org/wiki/Image_gradient

Page 23: Spatial image filtering - cse.sc.educse.sc.edu/~tongy/csce763/lectures/lect7.pdfToday’s Agenda • Spatial image filtering •Linear filters –Image Smoothing –Image sharpening

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

Page 24: Spatial image filtering - cse.sc.educse.sc.edu/~tongy/csce763/lectures/lect7.pdfToday’s Agenda • Spatial image filtering •Linear filters –Image Smoothing –Image sharpening

Laplacian for Image Sharpening

2

2

2

22

yf

xff

∂∂

+∂∂

=∇

2D Isotropic filters – rotation invariant

yxf

yf

xff

∂∂∂

+∂∂

+∂∂

=∇2

2

2

2

22 2

Laplacian operator

[ ]),(),(),(

2 yxfcyxfyxg

∇+

=

Image sharpening with Laplacian

Page 25: Spatial image filtering - cse.sc.educse.sc.edu/~tongy/csce763/lectures/lect7.pdfToday’s Agenda • Spatial image filtering •Linear filters –Image Smoothing –Image sharpening

Image Sharpening

Scale the Laplacian by shifting the intensity range to [0, L-1]

Page 26: Spatial image filtering - cse.sc.educse.sc.edu/~tongy/csce763/lectures/lect7.pdfToday’s Agenda • Spatial image filtering •Linear filters –Image Smoothing –Image sharpening

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

( )),(),(*),(),( yxfyxfkyxfyxg −+=0≥k

When k>1, it becomes a highboost filtering.

Page 27: Spatial image filtering - cse.sc.educse.sc.edu/~tongy/csce763/lectures/lect7.pdfToday’s Agenda • Spatial image filtering •Linear filters –Image Smoothing –Image sharpening

An Example

Page 28: Spatial image filtering - cse.sc.educse.sc.edu/~tongy/csce763/lectures/lect7.pdfToday’s Agenda • Spatial image filtering •Linear filters –Image Smoothing –Image sharpening

Gradient for Image Sharpening -- Example

An application in industrial defect detection.

Page 29: Spatial image filtering - cse.sc.educse.sc.edu/~tongy/csce763/lectures/lect7.pdfToday’s Agenda • Spatial image filtering •Linear filters –Image Smoothing –Image sharpening

Combining Spatial Enhancement Methods

Page 30: Spatial image filtering - cse.sc.educse.sc.edu/~tongy/csce763/lectures/lect7.pdfToday’s Agenda • Spatial image filtering •Linear filters –Image Smoothing –Image sharpening

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

Page 31: Spatial image filtering - cse.sc.educse.sc.edu/~tongy/csce763/lectures/lect7.pdfToday’s Agenda • Spatial image filtering •Linear filters –Image Smoothing –Image sharpening

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