You are on page 1of 30

Image Enhancement in the Spatial

Domain

Digital Image Processing


Lecture # 5
Topics for Today
• Basic Spatial Filtering (Mask processing)
• Types of filters
• Filter-mask or window or kernel
• Average filter (also know as Mean filter)
• Weighted average filter
• Median Filter
• Quiz
Types of Image Enhancement
• Point Processing
• Mask Processing
Types of filters
• Low-pass, high-pass and band-pass filters
• A low-pass filter attenuates high frequencies and retains low
frequencies unchanged. The result in the spatial domain is
equivalent to that of a smoothing filter; as the blocked high
frequencies correspond to sharp intensity changes.
• A high-pass filter, on the other hand, yields edge
enhancement or edge detection in the spatial domain,
because edges contain many high frequencies. Areas of rather
constant gray-level consist of mainly low frequencies and are
therefore suppressed.
• A band-pass attenuates very low and very high frequencies,
but retains a middle range band of frequencies. Band-pass
filtering can be used to enhance edges while reducing the
noise at the same time.
High frequency Vs Low frequency

In image we have intensity values (low and high)


Basic Idea of Filtering
Basic 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.
Filter Mask or Window or Kernel
Filter Mask or Kernel or Window
Box-filter
(Average/Mean filter)
Average/Mean Filter
• Mean filtering is a simple, intuitive and easy to implement
method of smoothing images by reducing the amount of
intensity variation between one pixel and the next. It is often
used to reduce noise in images.
• The idea of mean filtering is simply to replace each pixel value
in an image with the mean (`average') value of its neighbors,
including itself. This has the effect of eliminating pixel values
which are unrepresentative of their surroundings.
• A single pixel with a very unrepresentative value can
significantly affect the mean value of all the pixels in its
neighborhood.
• This may be a problem if sharp edges are required in the
output. Both of these problems are tackled by the median
filter, which is often a better filter for reducing noise than the
mean filter, but it takes longer to compute.
A simple example for averaging filter
Simple averaging filter
Averaging Filter application on image
Results are Image sharp area is
smooth and edges are blended
Application of Average Filter
MATLAB Session for Average Filter
Filter Mask or Kernel or Window
Box-filter Weighted average filter
(Average/Mean filter) (WAF)

(WAF) That pixels are multiplied by different coefficients, thus


giving more importance (weight) to some pixels at the expense
of others. In the mask shown in Fig (b) the pixel at the center of
the mask is multiplied by a higher value than any other, thus
giving this pixel more importance in the calculation of the
average.
Benefit of Weighted Average Filter
The basic strategy behind weighing 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.
Benefit of Average and Weighed
Average Filter
• An important application of spatial averaging
is to blur an image for the purpose getting a
gross representation of objects of interest,
such that the intensity of smaller objects
blends with the background and larger objects
become “bloblike” and easy to detect.
Example of 15-15 Averaging Mask
Order-Statistics Filters
(Non-Linear Filter)
• Order-statistics filters are nonlinear spatial filters whose response is based
on ordering (ranking) the pixels contained in the image area encompassed
by the filter, and then replacing the value of the center pixel with the value
determined by the ranking result.
• The best-known example in this category is the median filter, which, as its
name implies, replaces the value of a pixel by the median of the gray levels
in the neighborhood of that pixel (the original value of the pixel is included
in the computation of the median).
• Median filters are quite popular because, for certain types of random
noise, they provide excellent noise-reduction capabilities, with
considerably less blurring than linear smoothing filters of similar size.
Median filters are particularly effective in the presence of impulse noise,
also called salt-and-pepper noise because of its appearance as white and
black dots superimposed on an image.
Salt & Pepper Noise
• Salt-and-pepper noise is a form of noise
sometimes seen on images. It presents as
sparsely occurring white and black pixels. An
effective noise reduction method for this type
of noise is a median filter or a morphological
filter. (Salt=1 and pepper=0)
Median filter
• The median filter is normally used to reduce noise in an
image, somewhat like the mean filter. However, it often
does a better job than the mean filter of preserving
useful detail in the image.
• Median filter considers each pixel in the image in turn
and looks at its nearby neighbors to decide whether or
not it is representative of its surroundings. Instead of
simply replacing the pixel value with the mean of
neighboring pixel values, it replaces it with the median of
those values. The median is calculated by first sorting all
the pixel values from the surrounding neighborhood into
numerical order and then replacing the pixel being
considered with the middle pixel value.
Weighted average vs Median filter
• The median is a more robust average than the
mean and so a single very unrepresentative
pixel in a neighborhood will not affect the
median value significantly and it better
preserve sharp edges than the WA filter.
• One of the major problems with the median
filter is that it is relatively expensive and
complex to compute as it involves sorting.
Working of median filter
Working of median filter
What will be median for 3*3 area
Working of Median Filter
Working of Median Filter

You might also like