<< Chapter < Page Chapter >> Page >
g ( i , j ) = m e d i a n { f ( i - k , j - l ) } , ( k , l ) W

where W is a suitably chosen window. [link] shows the performance of the median filter in reducing so-called"salt and pepper" noise.

(1) Original gray scale image. (2) Original image degraded by "salt and pepper" noise with 0.05 noise density.(3) Result of 3 × 3 median filtering.

Smoothing exercise

Download the files race.tif , noise1.tif and noise2.tif for this exercise. Click here for help on the Matlab mesh command .

Among the many spatial lowpass filters, the Gaussian filter is of particular importance.This is because it results in very good spatial and spectral localization characteristics.The Gaussian filter has the form

h ( i , j ) = C exp ( - i 2 + j 2 2 σ 2 )

where σ 2 , known as the variance , determines the size of passband area. Usually the Gaussian filter is normalized by a scaling constant C such that the sum of the filter coefficient magnitudes is one, allowing the average intensity of the image to be preserved.

i , j h ( i , j ) = 1

Write a Matlab function that will create a normalized Gaussian filter that is centered around the origin (the center element of your matrix should be h ( 0 , 0 ) ). Note that this filter is both separable and symmetric , meaning h ( i , j ) = h ( i ) h ( j ) and h ( i ) = h ( - i ) . Use the syntax

h=gaussFilter(N, var)

where N determines the size of filter, var is the variance, and h is the N × N filter. Notice that for this filter to be symmetrically centered around zero, N will need to be an odd number.

Use Matlab to compute the frequency response of a 7 × 7 Gaussian filter with σ 2 = 1 . Use the command

H = fftshift(fft2(h,32,32));

to get a 32 × 32 DFT. Plot the magnitude of the frequency responseof the Gaussian filter, | H G a u s s ( ω 1 , ω 2 ) | , using the mesh command. Plot it over the region [ - π , π ] × [ - π , π ] , and label the axes.

Filter the image contained in the file race.tif with a 7 × 7 Gaussian filter, with σ 2 = 1 .

You can filter the signal by using the Matlab command Y=filter2(h,X); , where X is the matrix containing the input image and h is the impulse response of the filter.
Display the original and the filtered images, and notice the blurring that the filter has caused.

Now write a Matlab function to implement a 3 × 3 median filter (without using the medfilt2 command). Use the syntax

Y = medianFilter(X);

where X and Yare the input and output image matrices, respectively.For convenience, you do not have to alter the pixels on the border of X .

Use the Matlab command median to find the median value of a subarea of the image, i.e. a 3 × 3 window surrounding each pixel.

Download the image files noise1.tif and noise2.tif . These images are versions of the previous race.tif image that have been degraded by additive white Gaussian noise and "salt and pepper" noise, respectively.Read them into Matlab, and display them using image . Filter each of the noisy images with both the 7 × 7 Gaussian filter ( σ 2 = 1 ) and the 3 × 3 median filter. Display the results of the filtering, and place a title on each figure.(You can open several figure windows using the figure command.) Compare the filtered images with the original noisy images.Print out the four filtered pictures.

Inlab report

  1. Hand in your code for gaussFilter and medianFilter .
  2. Hand in the plot of | H G a u s s ( ω 1 , ω 2 ) | .
  3. Hand in the results of filtering the noisy images (4 pictures).
  4. Discuss the effectiveness of each filter for the case of additive white Gaussian noise. Discuss both positive and negative effectsthat you observe for each filter.
  5. Discuss the effectiveness of each filter for the case of "salt and pepper" noise. Again, discuss both positive andnegative effects that you observe for each filter.

Image sharpening

Image sharpening techniques are used primarily to enhance an image by highlighting details. Since fine details of an imageare the main contributors to its high frequency content, highpass filtering often increases the local contrast and sharpens theimage. Some typical highpass filter impulse responses used for contrast enhancement are shown in [link] . The frequency response of each of these filters is shown in [link] .

Impulse responses of highpass filters useful for image sharpening.
Frequency responses of the highpass filters shown in Fig. 9.

An example of highpass filtering is illustrated in [link] . It should be noted from this examplethat the processed image has enhanced contrast, however it appears more noisy than the original image.Since noise will usually contribute to the high frequency content of an image, highpass filtering has the undesirable effect of accentuatingthe noise.

(1) Original gray scale image. (2) Highpass filtered image.

Sharpening exercise

Download the file blur.tif for the following section.

In this section, we will introduce a sharpening filter known as an unsharp mask . This type of filter subtracts out the “unsharp” (low frequency) componentsof the image, and consequently produces an image with a sharper appearance.Thus, the unsharp mask is closely related to highpass filtering. The process of unsharp masking an image f ( i , j ) can be expressed by

g ( i , j ) = α f ( i , j ) - β [ f ( i , j ) * * h ( i , j ) ]

where h ( i , j ) is a lowpass filter, and α and β are positive constants such that α - β = 1 .

Analytically calculate the frequency response of the unsharp mask filter in terms of α , β , and h ( i , j ) by finding an expression for

G ( ω 1 , ω 2 ) F ( ω 1 , ω 2 ) .

Using your gaussFilter function from the "Smoothing Exercise" section, create a 5 × 5 Gaussian filter with σ 2 = 1 . Use Matlab to compute the frequency response of an unsharp mask filter(use your expression for [link] ), using the Gaussian filter as h ( i , j ) , α = 5 and β = 4 . The size of the calculated frequency response should be 32 × 32 . Plot the magnitude of this response in the range [ - π , π ] × [ - π , π ] using mesh , and label the axes. You can change the viewing angle of the mesh plot with the view command. Print out this response.

Download the image file blur.tif and read it into Matlab. Apply the unsharp mask filter with the parameters specified aboveto this image, using [link] . Use image to view the original and processed images. What effect did the filtering have on the image? Label the processedimage and print it out.

Now try applying the filter to blur.tif , using α = 10 and β = 9 . Compare this result to the previous one. Label the processedimage and print it out.

Inlab report

  1. Hand in your derivation for the frequency response of the unsharp mask.
  2. Hand in the labeled plot of the magnitude response. Compare this plot to the highpass responses of [link] . In what ways is it similar to these frequency responses?
  3. Hand in the two processed images.
  4. Describe any positive and negative effects of the filtering that you observe.Discuss the influence of the α and β parameters.

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




Source:  OpenStax, Purdue digital signal processing labs (ece 438). OpenStax CNX. Sep 14, 2009 Download for free at http://cnx.org/content/col10593/1.4
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Purdue digital signal processing labs (ece 438)' conversation and receive update notifications?

Ask