Image Processing Project
Image Processing Project
where p(x,y) and p(x,y) are the pixel intensities of the original and thresholded
images respectively at the location (x,y), and M(m,n) is the filter kernel. Thus the
kernel is slid over the image point by point and at each location the intensity value of
the new image is calculated based on the intensity of the corresponding pixel in the
original image and its surrounding pixels.
In this project we will be dealing with exclusively with 3 by 3 kernels. The
kernels corresponding to the three edge detectors used in this project are:
Convolution of this kernel with an image results in a new value for each pixel which
is equal to the mean of the original pixel value and its surrounding pixels. This results
in a smoothing out effect on the image.
Median Filtering
The median filter works in a way similar to the mean filter except that the value
of each new pixel is equal to the median of the original pixel value and its
surrounding pixels rather than the mean. The median filtering of an image using a 3
by 3 kernel may be represented by the following equation:
where the function median{ } determines the median of the numbers within the
parenthesis. The median filter is especially suited to eliminate spikes, such as those
found in salt and pepper noise, since the new pixel value is independent of
abnormally high or low values within corresponding sub-array.
2. Start Matlab
3. Read in, display and print the three images by executing the following commands:
[imgo,map]=imread('orig.bmp');
[imgn,map]=imread('rand.bmp');
[imgs,map]=imread('s_p.bmp');
4. Find the size of the original image matrix (imgo) and the map matrix (map) using
the size command. Answer the questions: size(imgo) = ? size(map) = ? How
many pixels does the image consist of? What is the maximum number of gray
levels possible in the image? List the map matrix simply by typing: map. Why are
the values of the elements in each row of the matrix the same?
5. Create three new maps using the following commands:
6. Enter the following commands to display the image imgo using each of the three
new maps:
Answer the questions: How do these three renderings of the image differ from the
original rendering? Why are the renderings different even though they use the
same image matrix? Why is the background for all three of the new renderings
still back?
7. The following Matlab function is to perform thresholding on the image:
0)
image
threshold
hi value
lo value
matrix
thresholded
percent
image
diseased
imgo
100
imgt100
pct100
imgo
175
imgt175
pct175
imgo
245
imgt245
pct245
[imgt100,pct100]=threshold(imgo,100,1,0);
pct100 = ? pct175 = ? pct245 = ? Why is the value obtained for pct100 smaller
then that obtained for pct245? How is this apparent when comparing the plots of
imgt100 and imgt245?
When we threshold the image to separate the healthy from the diseased tissue we
are assuming that the pixels corresponding to each group belong to different
populations and that a fixed threshold may distinguish one from the other. To test
whether this is true for our image we will calculate a histogram which has
gray-scale level as the x-axis and for which each column represents the number of
pixels having the corresponding gray-scale level. If our assumption regarding the
two populations is true we should see two peaks in the histogram, one
corresponding to the healthy tissue and the other to the diseased tissue. The
following function has been written to do this:
image = single(image);
Type in the following commands to plot the histogram for the original image (We
use lo=2 to ignore the background and hi=255 because this gives a nicer
histogram. If you dont believe try 256 instead!).
By looking at the histogram which of the three thresholds best separates the two
populations of tissue (100, 175, or 245)? Could you have chosen a better threshold
than this? If so what value would you have used and why?
8. Combine the three threshold images to form the image matrix imgtcmb and plot
and print this image using the following commands:
How does this combined image differ from the original image? How many bits
would be necessary to represent one pixel in this image? In what way does this
remind you of the quantization error discussed before in our class?
9. The following Matlab function has been written to perform the discrete
convolution of a 3 by 3 filter kernel with an image matrix.
Use this function to apply horizontal and vertical edge detectors and a Laplacian
filter to the imgt175 thresholded image we obtained in Step 8 as follows:
imgtbin = min(1,imgtbin);
imgtbin = double(imgtbin);
Do all the above edge detectors work (Yes/No)? What are their effects on the
image?
Before going to the next step, convert the matrices into the double format using
the commands:
imgo = double(imgo);
imgn = double(imgn);
imgs = double(imgs);
10. Use the mask_filter function to apply a mean filter to the original image:
With reference to the values of the mean filter kernel, describe and explain the
effect the filter had on the image?
11. Use the median_filter function to apply a median filter to the original image and
plot it below the mean filtered image on Figure 9:
Describe and explain the effect the Median filter had on the image? Compare and
contrast the effects of the mean and median filters on the original image with
special reference to shifts in the edges of the image outline and the image features
(i.e., the box and the two notches). In conclusion specify which of the two filters
introduces least distortion of the image.
12. In this last step we will examine the effect of mean and median filtering on
Gaussian white noise and salt and pepper noise. We will create six figures
which will enable comparison of corresponding images. To facilitate this job and
save you a lot of boring typing you have six Matlab m-files which will do the
work. These files are all similar to org_gaus.m, as given below:
By comparing Figure 10 to Figure 11, what is the main difference between the
Gaussian white noise and salt and pepper noise in terms of the noise pixel
intensity? Explain this in terms of the definition of the two types of noise.
Now, enter the following commands:
The commands should plot the original image contaminated by Gaussian noise at
the top, the same image after mean and median filtering respectively in the middle,
and the absolute difference between the two corresponding images at the bottom.
Compare these two figures together and with Figure 10 and answer the following
questions: Which of the two filters seems to have reduced the Gaussian noise
better? Explain what made you reach this conclusion. Also, by comparing the
unfiltered noise image to the mean filtered noise image describe the effect that the
filter had on the Gaussian noise and explain how this came about; repeat the above
question for the median filter.
Then, enter the following commands:
The commands should plot the original image contaminated by salt and pepper
noise at the top, the same image after mean and median filtering respectively in
the middle, and the absolute difference between the two corresponding images at
the bottom. Compare these two figures together and with Figure 11 and answer
the following questions: Which of the two filters seems to have reduced the salt
and pepper noise better? Explain what made you reach this conclusion. Also, by
comparing the unfiltered noise image to the mean filtered noise image describe the
effect that the filter had on the salt and pepper noise and explain how this came
about; repeat the above question for the median filter.