You have stored the image shown in
Figure (1) in bmp format at the beginning. If you haven't done
so, right click here (eb01
) to save the image in
your work directory.
Lab Activity (1)
Corrupt this image by the percentages given below and save the
resulting image in your MS Word file. Mark the images with the
5% Salt and Pepper
25% Salt and Pepper
50% Salt and Pepper
75% Salt and Pepper
100% Salt and Pepper
Let me ask you a question. You know what you have added in each part,
can you take the additive
noise back to obtain the original image back?
Similarly, you can corrupt the image using Gaussian noise. The
this type of noise is:
imnoise(f, 'gaussian', m, var)
is the mean and var
is the variance. The
default value of m
is 0 and
that of var
to the fact that imnoise converts the image to the range [0 1], you
to convert m and var based on the class type of the
example, for an image in uint8 class type, a Gaussian noise with mean
64 and variance of 400 will have m =
64/255 and var = 400/(2552).
In this lab activity, you are required to corrupt the original image
combinations of m
and var (4 cases ONLY)
. To help
you out with the
type of value you may want to select, I will explain how you can find
the mean and variance of the original image. This may give you an
idea of what kind of values you can choose for the reasonable mean and
>> mean(mean(f)) % will compute the mean of the image
>> sqrt(std(f(:))) % will compute the variance of the
image which is the sqrt of standard deviation
to display the 4
resulting noisy images and include them in your
inlab file. Mark the images clearly.
Once again, don't forget imnoise works in [0 1] range, so you need to
convert m and var.
Generating Spatial Random Noise with a Specified Distribution
In MATLAB, function imnoise2
be used to generate random noise based on a given Cumulative Distribution Function
The syntax for this function is:
imnoise2(type, M, N, a, b)
This generates an array R
size M-by-N whose elements are random numbers of the specified type
with parameters a
(See Page 148 for more details).
Example: The following command line:
r = imnoise2('gaussian', 100000, 1,
produces 100000 random values (M is 100000 and N is 1) with a Gaussian
distribution with mean of 0 and standard deviation of 1.
You can display the histogram of this distribution using:
p = hist(r, bins); % where you
set the number of bins, let's say 50
With 50 bins, I have produced:
more histogram using
two other types
as defined on Page
148. I let you choose two
types as you wish. You can use the default values
parameters that you need in each case.
Here are the types:
1) uniform -
numbers in the interval (a, b), default (0, 1).
2) salt & pepper -
of 0 with probability a, and number of 1 with probability b, default
for both is 0.05.
3) lognormal -
numbers with offset a and shape parameter b. Default is a = 1 and b =
4) rayleigh -
with parameter a and b. Defaults are a = 0 and b = 1.
5) exponential -
random numbers with parameters a and b. Defaults are a = 1, b
does not matter.
6) erlang -
random numbers with parameters a and b. B must be positive
integer. Defaults are a = 2 and b = 5.
In MATLAB, there is a function called roipoly
that allows you to select
a Region Of Interest (ROI) from an image to use as the noise
matrix. You can use the mouse's left button to select the area of
image that you wish to use as the noise. Remember that the less feature
you have the closer the selected area is to the actual noise.
>> clear % this clears the MATLAB memory
>> f = imread('eb01.bmp');
% now use the left mouse click to select a polygon that best describe
the noise, once done with the selection of last corners, press Enter
>> [B, c, r] = roipoly(f);
After you press Enter, you will get:
B which is the same size image as the original image but in binary, r
are pairs holding the coordinates of the corners of the polygon.
To view the mask, you can try: