0% found this document useful (0 votes)
11 views23 pages

Image Enhancement II-1-23

Uploaded by

Asha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views23 pages

Image Enhancement II-1-23

Uploaded by

Asha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 23

Image

Enhancement
II
Filtering
• It is applied for noise removal or to perform some
type of image enhancement
• Filtering can be done in the spatial domain as well
as frequency domain
• The operators we will discuss here are called spatial
filters since they operate on the raw image data in
the spatial domain
• They operate on the image data by considering small
neighborhoods in an image and returning the result
based on a linear or non-linear operations; moving
sequentially across and down the entire image
Spatial Filtering
Spatial Filtering

Linear Filters Non-linear Filters

Average Filtering Smoothing Order-statistics


(Lowpass Filtering) Filters Filters
Weighted Averaging Sharpening
High-boost Filters Filters Median Filters
Derivative Filters
Smoothing filters: used for blurring and for noise reduction
Sharpening filters: used to highlight fine detail in an image or to
enhance detail that has been blurred, either in error or as a
natural effect of a particular method of image acquisition
Linear Spatial Filtering

W (-1,-1) W (-1,0) W (-1,1)


Mask
coefficients,
W (0,-1) W (0,0) W (0,1) showing
Mask
coordinate
arrangement
W (1,-1) W (1,0) W (1,1)

Image f(x, y) f (x-1,y-1) f (x-1,y) f (x-1,y+1)

Pixels
Since the
of f (x,y-1) f (x,y) f (x,y+1) operations
image performed in the
section convolution are
under f (x+1,y-1) f (x+1,y) f (x+1,y+1) linear, these types
mask of filters are called
linear filters
Linear Spatial Filtering
• The process consists simply of moving the filter
mask from point to point in an image
• At each point (x, y), the response of the filter at that
point is calculated using a predefined relationship
• The response is given by a sum of products of the
filter coefficients and the corresponding image
pixels in the area spanned by the filter mask
• The coefficient w (0,0) coincides with image value
f (x, y), indicating that the mask is centered at (x, y)
when the computation of the sum of products takes
place
Linear Spatial Filtering
• For a 3x3 mask shown in figure, the response, R, of
linear filtering with the filter mask at a point (x, y)
in the image
R = w(-1,-1) f(x-1,y-1)+ w(-1,0) f(x-1,y)+……
+ w(0,0) f(x,y)+… + w(1,0) f(x+1,y)
+ w(1,1) f(x+1,y+1)
w(s,t) :(2a+1)×(2b+1) mask Where „a‟ & „b‟ are
nonnegative integers
• For a mask of size mxn, we assume that m = 2a+1 and
n = 2b+1
• Focus: mask of odd sizes, smallest meaningful size: 3x3
Linear Spatial Filtering
• In general, Linear filtering of an image f of size MxN
with a filter mask of size mxn is given by:
a b
g ( x, y )    w(s, t ) f ( x + s, y + t )
s   at   b

where a = (m -1)/2 and b = (n -1)/2


• To generate a complete filtered image this equation must be
applied for x = 0, 1, 2,…, M-1 and y = 0, 1, 2,…,N-1
– In this way, we are assured that the mask processes all pixels
in the image
• Nonlinear spatial filters also operate on neighborhoods, and the
mechanics of sliding a mask past an image are the same. They do
not explicitly use coefficients in the sum-of-products manner.
Linear Spatial Filtering
• Border Effects- Special Consideration
– For a small value of m and n, it is not that much
problem; otherwise we may loose substantial amount of
data
– Common procedures:
• Border strips are added and set to zero
• Rows and columns are considered to wrap around
• Limit the excursion of the center of the filter mask to a
distance no less than (n-1)/2 pixels from the border of
the original image
– The resulting filtered image will be smaller than the
original, but all the pixels in the filtered image will
have been processed with the full mask
Spatial Correlation and Convolution

• Correlation is the process of moving a filter mask


over the image and computing the sum of
products at each location, as explained

• The mechanics of convolution are the same,


except that the filter is first rotated by 1800
Spatial Correlation and Convolution
Spatial Correlation and Convolution

• See that convolution of


a function with an
impulse copies the
function at the location
of the impulse
• If the filter mask is
symmetric, correlation
and convolution yield
the same result
Spatial Correlation and Convolution

• Correlation a b
w( x, y ) f ( x, y )    w(s, t ) f ( x + s, y + t )
s   at   b
• Convolution
a b
w( x, y ) f ( x, y )    w(s, t ) f ( x  s, y  t )
s   at   b

where a = (m -1)/2 and b = (n -1)/2

Minus sign denotes 1800 rotation of f, which has been


done for notational simplicity and to follow convention
Spatial Correlation and Convolution
• Using correlation or convolution to perform spatial
filtering is a matter of preference
– Either can perform the function of the other by a simple
rotation of the filter
– Important is the filter mask used in a given filtering task be
specified in a way that corresponds to the intended operation
• The linear spatial filtering discussed here are based
on correlation
• Convolution filter, Convolution mask, Convolution
kernel  spatial filter (not necessarily used for true convolution)
• Convolving a mask with an image is often used to
denote the sliding, sum-of-products process
Linear Filtering: Vector Representation

• It is convenient to write the response R of


an m x n mask at any point (x, y) is:
mn
R  w1 z1 + w2 z 2 + ... + wmn z mn   wi zi
i i

ws are the coefficients of an m x n W1 W2 W3


filter and the zs are the corresponding
W4 W5 W6
image intensities encompassed by
the filter W7 W8 W9
Generating Spatial Filter Mask
• Mask Coefficient
– Proper selection of the coefficients and application of
the mask at each pixel position in an image makes
possible a variety of useful image operations
• Noise reduction
• Region thinning
• Edge detection
– Coefficients are selected based on what the filter is
supposed to do, keeping in mind that all we can do with
linear filtering is to implement a sum of products
• Applying a mask at each pixel location in an image
is a computationally extensive task
Generating Spatial Filter Mask
• Example:
0 1 0
Consider the image: 1 1 1
0 0 1
Suppose the second row of the image is to be
highlighted, what is the mask that is needed?
Generating Spatial Filter Mask
• One interesting observation:
– Overall effect can be predicted on the general pattern, if
one uses convolution mask
• If the sum of coefficients of the mask is one,
average brightness of the image will be retained
• If the sum of coefficients of the mask is zero,
average brightness of the image will be lost and
will return a dark image
• If coefficients are alternating positive and negative,
the mask is a filter that will sharpen an image
• If coefficients are all positive, it is a filter that will
blur the image
Smoothing Spatial Filters
• Used for blurring and for noise reduction
• Blurring is used in preprocessing steps, such as
– Removal of small details from an image prior to large
object extraction, and
– Bridging of small gaps in lines or curves
• Noise reduction can be accomplished by blurring
with a linear filter and also by nonlinear filtering
• The output/response of a smoothing, linear spatial
filter is simply the average of the pixels contained
in the neighborhood of the filter mask
• Also called „Averaging Filters‟ or „Lowpass
Filters‟
Smoothing Linear Filters
• Replacing the value of every pixel in an image by the
average of the gray levels in the neighborhood will reduce
the “sharp” transitions in gray levels
• Sharp intensity transitions
– random noise in the image
– edges of objects in the image
• Thus, smoothing can reduce noises (desirable) and blur
edges (undesirable)
• Other uses
– smoothing of false contours resulting from using an insufficient
number of intensity levels
– reduction of irrelevant detail in an image (here, “irrelevant”
means pixel regions that are small wrt the size of filter mask)
General Form : Smoothing Mask
• Filter of size m x n (m and n odd)
a b

  w(s, t ) f ( x + s, y + t )
g ( x, y )  s   at   b
a b

  w(s, t )
s   at   b

summation of all coefficient of the mask (computed once)

The complete filtered image is obtained by applying the operation


for x = 0, 1, 2, …., M – 1 and y = 0, 1, 2, …., N - 1
3x3 Smoothing Linear Filters

box filter weighted average

the center is the most important and


other pixels are inversely weighted as
a function of their distance from the
center of the mask
Weighted Average Filter
• The basic strategy behind weighting the center
point the highest and then reducing the value of
the coefficients as a function of increasing
distance from the origin is simply an attempt to
reduce blurring in the smoothing process.

Weighted Average
Filter
Example 1
(a) Original image of size
a b 500x500 pixel
c d (b)-(f) Results of smoothing with
e f square averaging filter masks of
sizes n = 3, 5, 9, 15, and 35
respectively
Note:
- details that are of approx. the
same size as the filter mask are
affected considerably more
- the size of the mask establishes
the relative size of the objects
that will be blended with the
background
- big mask is used to eliminate
small objects from an image

You might also like