L2 - Image Enhancement Spatial Spatial Filtering
L2 - Image Enhancement Spatial Spatial Filtering
Spatial Filtering
Some figures are provided by Pearson Education, Digital Image Processing, Gonzalez & Woods, www.ImageProcessingPlace.com
Image Operations
• Arithmetic Operations on pixels (p and q are images)
– p+q
– p-q
– p*q (also stated as pq, or p x q)
– p%q
http://en.wikipedia.org/wiki/Digital_subtraction_angiography
Image Operation
• Addition can blend two images
Logic Operators
• NOT
black = 1, white = 0.
Logic Operators
• AND
black = 1, white = 0.
Logic Operators
• OR
black = 1, white = 0.
• XOR?
Image Averaging
• If you can capture a scene or acquire an image repeatedly,
then averaging all the observed images will give you a
clear image with less noise.
1 K
g ( x, y ) =
K
∑ g ( x, y )
i =1
i
Image Averaging
• It follows that
Variance of the 1 2
σ 2
g ( x, y ) = σ η ( x, y )
average image K
K=8 K=16
K=64 K=128
The figure is provided by Pearson Education, Digital Image Processing, Gonzalez & Woods, www.ImageProcessingPlace.com
Spatial Filtering using a Mask/Filter
• Neighborhood operators
mask/filter
z1 z2 z3 w1 w2 w3
z4 z5 z6 w4 w5 w6
z7 z8 z9 w7 w8 w9
𝑔𝑔 𝑥𝑥, 𝑦𝑦
= 𝑤𝑤 −1, −1 𝑓𝑓 𝑥𝑥 − 1, 𝑦𝑦 − 1 + ⋯
+ 𝑤𝑤 1,1 𝑓𝑓(𝑥𝑥 + 1, 𝑦𝑦 + 1)
The figure is provided by Pearson Education, Digital Image Processing, Gonzalez & Woods, www.ImageProcessingPlace.com
Response of a linear mask/filter
The figure is provided by Pearson Education, Digital Image Processing, Gonzalez & Woods, www.ImageProcessingPlace.com
Smoothing Filters
• Smoothing Filters
– blurring
• “pre-processing”
– removal of small details before object extraction
– noise reduction
• removal of noise in an image
• Often called “Low-Pass” Filters
– Filter lets low-frequencies pass
– Stops high-frequencies
Low-pass spatial filtering
0
0
Filter center
Frequency Domain Spatial Domain
Low-pass spatial filtering
• Only requirement for a low-pass
filter is that wi be positive
w1 w2 w3
• Note that the result can be larger
w4 w5 w6 than the valid output range(L-1)
w7 w8 w9
• Can pre-scale the filter
scale_factor = (Σ wi )-1
Low-pass spatial filter
1 1 1
1/9 * 1 1 1
1 1 1
Average Filter
(Box Filter)
Extends to larger filters
1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1
1 1 1
1 1 1 1 1 1 1 1 1
1/9 * 1 1 1 1/81 *
1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1
Example
The figure is provided by Pearson Education, Digital Image Processing, Gonzalez & Woods, www.ImageProcessingPlace.com
Example
Smooth image
Original image 15x15 averaging filter thresholded image
The figure is provided by Pearson Education, Digital Image Processing, Gonzalez & Woods, www.ImageProcessingPlace.com
Example
The figure is provided by Pearson Education, Digital Image Processing, Gonzalez & Woods, www.ImageProcessingPlace.com
Other arrangements
1 1 1 1 1
1 1 1
1 2 3 2 1
1 3 4 3 1
1 2 1
1 2 3 2 1
1 1 1
1 1 1 1 1
The figure is provided by Pearson Education, Digital Image Processing, Gonzalez & Woods, www.ImageProcessingPlace.com
Gaussian Filter
𝑠𝑠 2 +𝑡𝑡 2
−
𝑤𝑤 𝑠𝑠, 𝑡𝑡 = 𝐾𝐾𝑒𝑒 2𝜎𝜎2
The figure is provided by Pearson Education, Digital Image Processing, Gonzalez & Woods, www.ImageProcessingPlace.com
Gaussian Filter
The figure is provided by Pearson Education, Digital Image Processing, Gonzalez & Woods, www.ImageProcessingPlace.com
Linear vs. Non-linear
• Linear Filters
– Linear operation (output can be expressed as the
convolution of the input image with filter)
– Have corresponding frequency domain filter
• Non-linear Filters
– Examine neighbors using various orderings
• Often use Order Statistics
Median Filter
• Very popular non-linear filter
• Find the median of the window
• Preserves edges
• Removes impulse noise, avoids excessive smoothing
2 3 8
neighbor sort = {2,2,3,3,4,4,8,9,10}
3 4 10
4 2 9
f(x,y) = median
pixel values about (x,y)
window 3x3
Examples
The figure is provided by Pearson Education, Digital Image Processing, Gonzalez & Woods, www.ImageProcessingPlace.com
Median Filter
• Often referred to as “de-speckle operation”
• It converges
– That is, if you perform it over and over for many
times, eventually the image will not change.
Iterative Smoothing
• Local Averaging
– Converges to an image with constant intensity
• Median Filter
– Converges to an image invariant to the filter
Sharpening
• Objectives of sharpening
– Highlight fine details in an image
– Enhance details that have been blurred
– We can think of this as high-pass filtering
• Letting high frequencies pass
• Removing low frequencies
First Order Derivatives
• Gradient
• Function of 2 variables x, y
∂f y
∂x
∇f =
∂f
∂y
x
First Order Derivatives
• For each (x,y) you are storing two values:
∂f
∂x
∇f =
∂f
∂y
• Often have two images to represent this
• X-Gradient and Y-Gradient
– Can be computed independently
First Order Derivatives
• X-Gradient and Y-Gradient y
x
Original |∂f/∂x|
| ∂f/∂y| mag(∇f)
Gradient
• Gradient Magnitude
2 1/ 2
∂f ∂f
2
mag(=
∇f) +
∂x ∂y
Basic Derivative
• Consider the pixels z1 z2 z3
z4 z5 z6
z7 z8 z9
mag(∇f ) ≈| z5 − z6 | + | z5 − z8 |
Basic Derivative
z1 z2 z3
z4 z5 z6
z7 z8 z9
mag(∇f ) ≈| ( z7 + z8 + z9 ) − ( z1 + z2 + z3 ) | +
| ( z3 + z6 + z9 ) − ( z1 + z4 + z7 ) |
-1 0 1 -1 -1 -1
-1 0 1 0 0 0
-1 0 1 1 1 1
mag(∇f ) ≈| ( z7 + z8 + z9 ) − ( z1 + z2 + z3 ) | +
| ( z3 + z6 + z9 ) − ( z1 + z4 + z7 ) |
First Order Derivatives
• Sobel operator
-1 0 1 -1 -2 -1
-2 0 2 0 0 0
-1 0 1 1 2 1
The figure is provided by Pearson Education, Digital Image Processing, Gonzalez & Woods, www.ImageProcessingPlace.com
Unsharp Masking and Highboost Filtering
̅ 𝑦𝑦)
1. Blur the original image 𝑓𝑓(𝑥𝑥, 𝑦𝑦) to generate 𝑓𝑓(𝑥𝑥,
̅ 𝑦𝑦))
𝑔𝑔 𝑥𝑥, 𝑦𝑦 = 𝑓𝑓 𝑥𝑥, 𝑦𝑦 + 𝑘𝑘(𝑓𝑓 𝑥𝑥, 𝑦𝑦 − 𝑓𝑓(𝑥𝑥,
Unsharp Masking and Highboost Filtering
The figure is provided by Pearson Education, Digital Image Processing, Gonzalez & Woods, www.ImageProcessingPlace.com
Unsharp Masking and Highboost Filtering
The figure is provided by Pearson Education, Digital Image Processing, Gonzalez & Woods, www.ImageProcessingPlace.com
Sharpening
Values can be either
positive or negative
1
0
0
Filter center
-1 -1 -1
• Note, the sum of the coefficients is
zero
1/9 * -1 8 -1
Original High-Pass
Second Order Derivatives
• The Laplacian operator
𝜕𝜕 2 𝑓𝑓 𝜕𝜕 2 𝑓𝑓
∇2 𝑓𝑓 = 2 + 2
𝜕𝜕𝑥𝑥 𝜕𝜕𝑦𝑦
∇2 𝑓𝑓
= 𝑓𝑓 𝑥𝑥 + 1, 𝑦𝑦 + 𝑓𝑓 𝑥𝑥 − 1, 𝑦𝑦
+ 𝑓𝑓 𝑥𝑥, 𝑦𝑦 + 1 + 𝑓𝑓 𝑥𝑥, 𝑦𝑦 − 1
− 4𝑓𝑓(𝑥𝑥, 𝑦𝑦)
Second Order Derivatives
The figure is provided by Pearson Education, Digital Image Processing, Gonzalez & Woods, www.ImageProcessingPlace.com
Second Order Derivatives
The figure is provided by Pearson Education, Digital Image Processing, Gonzalez & Woods, www.ImageProcessingPlace.com
Laplacian for sharpening
𝑓𝑓(𝑥𝑥, 𝑦𝑦) ∇2 𝑓𝑓(𝑥𝑥, 𝑦𝑦)
𝑔𝑔 𝑥𝑥, 𝑦𝑦
= 𝑓𝑓 𝑥𝑥, 𝑦𝑦 + 𝑐𝑐[∇2 𝑓𝑓(𝑥𝑥, 𝑦𝑦)]
The figure is provided by Pearson Education, Digital Image Processing, Gonzalez & Woods, www.ImageProcessingPlace.com