You are on page 1of 16

EE 5356 - DlGlTAL lMAGE PROCESSlNG - PROJECT 4

NON-LlNEAR FlLTERlNG
Read any 256x256 or 5l2x5l2 grayscale image. Add the following types of noise to it to
generate 4 noisy images:
l. Gaussian noise
2. Poisson noise
3. Salt & pepper noise
4. Speckle noise
Apply the following spatial filters to the noisy images:
l. Arithmetic mean
2. Geometric mean
3. Harmonic mean
4. Contra-harmonic mean
5. Median filter
6. Min
7. Max
8. Mid-point
9. Alpha trimmed mean filter
Submit the following with your code:
l. Print
a. the original image,
b. the noisy images, and
c. the results of all the filters on each noisy image.
2. Determine which type of filtering worked well for each type of noise.
References:
l. Rafael C. Gonzalez and Richard E. Woods, "Digital lmage Processing", lll edition,
Prentice Hall, pages 322-325, 2008.
2. Gonzalez, Woods and Eddins, "Digital lmage Processing with MATLB", l edition,
Prentice Hall, pages l60-l64, 2009.
Types of Noise
l. Gaussian noise - Gaussian noise is statistical noise that has a probability density
function of the normal distribution (also known as Gaussian distribution). ln other words,
the values that the noise can take on are Gaussian-distributed. lt is most commonly
used as additive white noise to yield additive white Gaussian noise (AWGN).
2. Poisson noise - Poisson noise has a probability density function of a Poisson
distribution.
3. Salt & pepper noise - lt represents itself as randomly occurring white and black pixels.
An effective noise reduction method for this type of noise involves the usage of a median
filter. Salt and pepper noise creeps into images in situations where quick transients,
such as faulty switching, take place. The image after distortion from salt and pepper
noise looks like the image attached.
4. Speckle noise - Speckle noise is a granular noise that inherently exists in and degrades
the quality of images. Speckle noise is a multiplicative noise, i.e. it is in direct proportion
to the local grey level in any area. The signal and the noise are statistically independent
of each other.
Adding noise to images
MATLAB provides a function 'imnoise' to conveniently add the desired type of noise to an
image. For e.g.
m = 0;
v = 0.01;
J1 = imnoise(I,'gaussian',m,v);
Adds Gaussian noise with mean=0 and variance=0.0l to the image. See MATLAB's
documentation for 'imnoise'. Use MATLAB's default parameters when none have been specified
here.
Filter descriptions
Corrupted image Filtered image
Sxy = set of coordinates in a rectangular subimage window (neighborhood) of size (m x n)
centered at point (x,y).
n
l. Arithmetic mean filter: This filter computes the average value of the pixels intensity
values in the sub-image (of size m x n).
2. Geometric mean filter: lt is similar to an arithmetic mean filter, but it tends to lose less
detail in the process.
3. Harmonic mean filter: This filter computes the harmonic mean of the pixels intensity
values.
4. Contraharmonic mean filter: This filter computes the contraharmonic mean of the pixels
intensity values. Note that the contraharmonic filter reduces to the mean filter for Q = 0,
and to the harmonic mean filter for Q = -l.
m
Center
(x,y)
(3 x 3) window
5. Median filter: Replaces the value of the pixel by the median of the pixels in the sub-
image.
6. Max filter: For d = l, replaces the value of the pixel by the maximum of the pixel intensity
values in the sub-image. For d>l, uses the mean of the top d values.
7. Min filter: For d = l, replaces the value of the pixel by the minimum of the pixel intensity
values in the sub-image. For d>l, uses the mean of the lowest d values.
8. Mid-point filter: Replaces the value of the pixel by the mid-point of the pixels in the sub-
image.
9. Alpha trimmed mean filter: Replaces the value of the pixel by the mean of the remaining
pixel intensity values after discarding the top d/2 and lowest d/2 intensity values.
Reference: Pages 322-325 of textbook.
Taken from: Gonzalez, Woods and Eddins, "Digital lmage Processing with MATLB", l edition,
Prentice Hall, 2009, page l60.
Filtering the image
Filtering the image is a neighborhood operation. The 3x3 neighborhood of a pixel (x,y) is shown:
(source:
http://www.comp.dit.ie/bmacnamee/m
aterials/dip/lectures/lmageProcessing
5-SpatialFilteringl.ppt)
Linear filters can be implemented by multiplying the pixel neighborhood with the filter kernel.
This is done conveniently using the 'imfilter' function. But in this project, with the exception of
the averaging filter, all other filters are non-linear filtering operations and cannot be implemented
using 'imfilter'.
There are several other ways to implement non-linear filtering in MATLAB:
l. 'nlfilter' general sliding neighborhood operations.
2. 'colfilt' column wise neighborhood operations. This is a bit more complex to implement
than 'nlfilt', but is optimized for speed.
3. 'ordfilt2' performs order statistic filtering. lt is only applicable to median, mid-point,
min, and max filters.
Please see the MATLAB documentation for these functions. They have several examples to
illustrate their usage.
Typical usage of one of these functions is:
result = nlfilter(im, [M N], @fun);
Where im in the input image, [M N] is the neighborhood size, typically [3 3], and @fun is a
function handle. The output image is stored in result. This function will extract the
neighborhood for every pixel in the image and call fun with the neighborhood as the parameter.
'fun' will process these pixels (for e.g. computes the geometric mean of the values) and produce
a resulting pixel value. 'fun' can be a MATLAB built-in function or a function you wrote.
A simple (but inefficient) example of a geometric mean filter:
in main
im = !ou"le(im);
Note#1
gmean$result = nlfilter(im, [M N], @gmean);
gmean$result = uint%(gmean$result);
Note#1
in gmean.m
fun&tion v = gmean(')
[M N] = si(e(');
)ro! = 1;
for i=1*M
for +=1*N
)ro! = )ro! , '(i,+);
en!
en!
v = )ro! - (1.MN);
Note-1: We cast the image to double before calling nlfilter, and cast the result back to uint8:
im = double(im);
gmean_result = nlfilter(im, [M N], @gmean);
gmean_result = uint8(gmean_result);
This is needed as uint8 (default type for grayscale images) is limited to 255 which is insufficient
in capacity and does not support most math functions
Example results
Original image
Original image
Gaussian noise
Poisson noise
Salt & pepper noise
Speckle noise
Gaussian noise Poisson
Salt & pepper Speckle
Arithmetic mean filter
Gaussian noise Poisson
Salt & pepper Speckle
Geometric mean filter
Gaussian noise Poisson
Salt & pepper Speckle
Harmonic mean filter
Gaussian noise Poisson
Salt & pepper Speckle
Contra-harmonic mean filter
Gaussian noise Poisson
Salt & pepper Speckle
Median filter
Gaussian noise Poisson
Salt & pepper Speckle
Midpoint filter
Gaussian noise Poisson
Salt & pepper Speckle
Min filter (d=5)
Gaussian noise Poisson
Salt & pepper Speckle
Max filter (d=5)
Filtering:
C C

Window Slide window by l pel to the right


C: center pixel
Example: Arithmetic Mean:
!
( , )
"
( , ) ( , )
xy
s t
f x y g s t S
m n
=


= filtered pel
--------- m ---------

-
-
-
-
-

n

-
-
-
-
-
-
-

Slide the (3x3) window to one pel to the right. Replace the center pel by the mean of the new
(3x3) window. For filtering, always use the original pels, not the filtered pels. This is applicable
to all types of filtering.
At the vertical and horizontal edges (borders) extend by mirroring, i.e.
X02 X0l X00 X00 X0l X02.
Xl2 Xll Xl0 Xl0 Xll Xl2.
vertical edge
This padding is done before filtering. See help for the function 'padarray'. After filtering, the extra
padded pixels should be removed.

You might also like