Transcript Digital Image Processing
4/30/2020
Digital Image Processing
Image Enhancement Spatial Filtering
Duong Anh Duc - Digital Image Processing 1
Image Enhancement: Spatial Filtering
Image enhancement in the spatial domain can be represented as: Transformation Enhanced Image
g(m,n) = T(f)(m,n)
Given Image The transformation
T
maybe linear or nonlinear. We will mainly study linear operators
T
but will see one important nonlinear operation. 4/30/2020 Duong Anh Duc - Digital Image Processing 2
How to specify T
If the operator
T
is linear and shift invariant (LSI), characterized by the point spread sequence (PSS)
h(m,n)
, then (recall convolution) 4/30/2020 Duong Anh Duc - Digital Image Processing 3
How to specify T
In practice, to reduce computations,
h(m,n)
of “finite extent: where
h
(
k,l
)
= 0
for (
k,l
) is a small set (called neighborhood). is is also called as the support of
h
. In the frequency domain, this can be represented as:
G
(
u,v
) =
H e
(
u,v
)
F e
(
u,v
) where
H e
(
u,v
) and
F e
(
u,v
) are obtained after appropriate zeropadding.
4/30/2020 Duong Anh Duc - Digital Image Processing 4
How to specify T
Many LSI operations can be interpreted in the frequency domain as a “filtering operation.” It has the effect of filtering frequency components (passing certain frequency components and stopping others). The term
filtering
is generally associated with such operations. 4/30/2020 Duong Anh Duc - Digital Image Processing 5
How to specify T
Examples of some common filters (1-D case): Lowpass filter Highpass filter 4/30/2020 Duong Anh Duc - Digital Image Processing 6
If
h
(
m
,
n
) is a 3 by 3 mask given by
w 1 w 2 w 3 h
=
w 4 w 5 w 6 w 7 w 8 w 9
then 4/30/2020 Duong Anh Duc - Digital Image Processing 7
The output
g
(
m
,
n
) is computed by sliding the mask over each pixel of the image
f
(
m
,
n
). This filtering procedure is sometimes referred to as
moving average
filter. Special care is required for the pixels at the border of image
f
(
m
,
n
). This depends on the so-called boundary condition. Common choices are: The mask is truncated at the border (
free boundary
) The image is extended by appending extra rows/columns at the boundaries. The extension is done by repeating the first/last row/column or by setting them to some constant (
fixed boundary
). The boundaries “wrap around” (
periodic boundary
). 4/30/2020 Duong Anh Duc - Digital Image Processing 8
In any case, the final output
g
(
m
,
n
) is restricted to the support of the original image
f
(
m
,
n
). The mask operation can be implemented in MATLAB using the filter2 command, which is based on the conv2 command. 4/30/2020 Duong Anh Duc - Digital Image Processing 9
Smoothing Filters
Image smoothing refers to any image-to-image transformation designed to “smooth” or flatten the image by reducing the rapid pixel-to-pixel variation in grayvalues. Smoothing filters are used for:
Blurring
: This is usually a preprocessing step for removing small (unwanted) details before extracting the relevant (large) object, bridging gaps in lines/curves,
Noise reduction
: Mitigate the effect of noise by linear or nonlinear operations. 4/30/2020 Duong Anh Duc - Digital Image Processing 10
Image smoothing by averaging (lowpass spatial filtering)
Smoothing is accomplished by applying an
averaging mask
.
An averaging mask is a mask with positive weights, which sum to 1. It computes a weighted average of the pixel values in a neighborhood. This operation is sometimes called
neighborhood averaging
. Some 3 x 3 averaging masks: This operation is equivalent to lowpass filtering. 4/30/2020 Duong Anh Duc - Digital Image Processing 11
Example of Image Blurring
4/30/2020 Original Image Duong Anh Duc - Digital Image Processing Avg. Mask 12
Example of Image Blurring
4/30/2020
N
= 3 Duong Anh Duc - Digital Image Processing
N
= 7 13
Example of Image Blurring
4/30/2020
N
= 11 Duong Anh Duc - Digital Image Processing
N
= 21 14
Example of noise reduction
4/30/2020 Noise-free Image Duong Anh Duc - Digital Image Processing 15
Example of noise reduction
4/30/2020 Zero-mean Gaussian noise, Variance = 0.01
Duong Anh Duc - Digital Image Processing 16
Example of noise reduction
4/30/2020 Zero-mean Gaussian noise, Variance = 0.05
Duong Anh Duc - Digital Image Processing 17
Median Filtering
The averaging filter is best suited for noise whose distribution is Gaussian: The averaging filter typically blurs edges and sharp details.
The median filter usually does a better job of preserving edges.
Median filter is particularly suited if the noise pattern exhibits strong (positive and negative) spikes.
Example
: salt and pepper noise.
4/30/2020 Duong Anh Duc - Digital Image Processing 18
Median Filtering
Median filter is a
nonlinear filter
, that also uses a mask. Each pixel is replaced by the median of the pixel values in a neighborhood of the given pixel.
Suppose
A
={
a 1
,
a 2
, …,
a k
} are the pixel values in a neighborhood of a given pixel with
a 1
a 2
…
a k
. Then Note: Median of a set of values is the “center value,” after sorting.
For example: If
A
6.
={0,1,2,4,6,6,10,12,15} then median(
A
) = 4/30/2020 Duong Anh Duc - Digital Image Processing 19
Example of noise reduction
Gaussian noise: s = 0.2 Salt & Pepper noise: prob. = 0.2
4/30/2020 MSE = 0.0337 MSE = 0.062 Duong Anh Duc - Digital Image Processing 20
Example of noise reduction
Output of 3x3 Averaging filter 4/30/2020 MSE = 0.0075
MSE = 0.0125
Duong Anh Duc - Digital Image Processing 21
Example of noise reduction
Output of 3x3 Median filter 4/30/2020 MSE = 0.0089
MSE = 0.0042
Duong Anh Duc - Digital Image Processing 22
Image Sharpening
This involves highlighting fine details or enhancing details that have been blurred.
4/30/2020 Before After Sharpening Duong Anh Duc - Digital Image Processing 23
Basic highpass spatial filtering
This can be accomplished by a linear shift invariant operator, implemented by means of a mask, with positive and negative coefficients.
This is called a sharpening mask, since it tends to enhance abrupt graylevel changes in the image.
The mask should have a positive coefficient at the center and negative coefficients at the periphery. The coefficients should sum to zero.
4/30/2020 Duong Anh Duc - Digital Image Processing 24
Basic highpass spatial filtering
Example: This is equivalent to
highpass filtering
.
A highpass filtered image
g
can be thought of as the difference between the original image
f
and a lowpass filtered version of
f
:
g(m,n) = f(m,n) – lowpass(f(m,n))
4/30/2020 Duong Anh Duc - Digital Image Processing 25
Example
4/30/2020 Original Image Highpass filtering Duong Anh Duc - Digital Image Processing 26
High-boost filtering
This is a filter whose output
g
is produced by subtracting a lowpass (blurred) version of
f
from an amplified version of
f g(m,n) = Af(m,n) – lowpass(f(m,n))
This is also referred to as
unsharp masking
.
4/30/2020 Duong Anh Duc - Digital Image Processing 27
High-boost filtering
Observe that
g(m,n) = Af(m,n) – lowpass(f(m,n)) = (A-1)f(m,n) + f(m,n) – lowpass(f(m,n))
= (A-1)f(m,n) + hipass(f(m,n))
For 1 >
A
, part of the original image is added back to the highpass filtered version of
f
.
The result is the original image with the edges enhanced relative to the original image.
4/30/2020 Duong Anh Duc - Digital Image Processing 28
Example
Original Image 4/30/2020 Highpass filtering High-boost filtering Duong Anh Duc - Digital Image Processing 29
Derivative filter
Averaging tends to blur details in an image. Averaging involves summation or integration.
Naturally, differentiation or “differencing” would tend to enhance abrupt changes, i.e., sharpen edges.
Most common differentiation operator is the gradient: 4/30/2020 Duong Anh Duc - Digital Image Processing 30
Derivative filter
The magnitude of the gradient is: Discrete approximations to the magnitude of the gradient is normally used. 4/30/2020 Duong Anh Duc - Digital Image Processing 31
Derivative filter
Consider the following image region:
z 1 z 2 z 3 z 4 z 5 z 6
z 7 z 8 z 9
We may use the approximation: 4/30/2020 Duong Anh Duc - Digital Image Processing 32
Derivative filter
This can implemented using the masks: As follows: 4/30/2020 Duong Anh Duc - Digital Image Processing 33
Derivative filter
Alternatively, we may use the approximation: This can implemented using the masks: As follows: 4/30/2020 Duong Anh Duc - Digital Image Processing 34
Derivative filter
The resulting maks are called
Roberts cross-gradient operators
. The Roberts operators and the Prewitt/Sobel operators (described later) are used for edge detection and are sometimes called edge detectors.
35 4/30/2020 Duong Anh Duc - Digital Image Processing
Example: Roberts cross-gradient operator
4/30/2020 Duong Anh Duc - Digital Image Processing 36
Example: Roberts cross-gradient operator
4/30/2020 Duong Anh Duc - Digital Image Processing 37
Prewitt operators
Better approximations to the gradient can be obtained by: This can be implemented using the masks: as follows: 4/30/2020 Duong Anh Duc - Digital Image Processing 38
Sobel operators
Another approximation is given by the masks: The resulting masks are called
Sobel operators
. 4/30/2020 Duong Anh Duc - Digital Image Processing 39
Example
4/30/2020 Prewitt Duong Anh Duc - Digital Image Processing Sobel 40