Uploaded by michikokin.iris

T5 - Noise

advertisement
(Image Processing using Matlab)
Technical
5
(Noise)
Name of Student
Michaella Gonzales
Date Performed
03/03/2023
Name of Professor
Mr. Abraham Magpantay
Date Submitted
03/03/2023
I. OBJECTIVES
At the end of the experiment students must be able to:
Cognitive
a.) understand the different types of noise on an image
Psychomotor:
a.) perform noise cleaning using different filters
Affective
a.) appreciate noise cleaning on an image
II. BACKGROUND INFORMATION
To accomplish this task, the student must have a clear understanding of the following topics:
 Images in Matlab
 Point Processing
 Spatial Filtering
 Noise
III. PROCEDURES
Write a Matlab script that will perform the following, take a screenshot of your output and
paste it on a word document together with your script. Indicate the question number that
corresponds to your answer:
1. The arrays below represent small greyscale images. Compute the 4 x 4 image that would result in each
case if the middle 16 pixels were transformed using a 3 x 3 median filter:
2. Using the same images from 1, transform them using 3 x 3 averaging filter.
3. Compare the results from 1 and 2.
4. Produce a grey subimage of the image flowers.tif by using the following Matlab commands:
Then add 5% ‘salt & pepper’ noise to the greyscale image. Attempt to remove the noise with
a) average filtering
b) median filtering
c) the outlier method
Which method gives the best result?
5. Use the grey image from question 4, but with 20% ‘salt & pepper’ noise. Compare the results with 5 x 5
median filter, and two applications of a 3 x 3 median filter. Which of the two produced a better result?
Optional:
6.
1. %T5Q1_GONZALES,MICHAELLA%
img = [8 17 4 10 15 12; 10 12 15 7 3 10; 15 10 50 5 3 12;
4 8 11 4 1 8; 16 7 4 3 0 4; 16 24 19 3 20 10];
filtered = zeros(size(image));
for i = 2:size(image, 1)-1
for j = 2:size(image, 2)-1
window = image(i - 1:i + 1, j - 1:j+1);
medianval = median(window(:));
filtered(i,j) = medianval;
end
end
subplot(1,2,1);
imshow(img,[]);
title('Original Image');
subplot(1,2,2);
imshow(filtered,[]);
title('Median filtered image:')
2. %T5Q1_GONZALES,MICHAELLA%
img = [8 17 4 10 15 12; 10 12 15 7 3 10; 15 10 50 5 3 12;
4 8 11 4 1 8; 16 7 4 3 0 4; 16 24 19 3 20 10];
f = ones(3)/9;
fi = conv2(img,f,'same');
subplot(1,2,1);
imshow(img,[]);
title('Original Image');
subplot(1,2,2);
imshow(fi,[]);
title('Average Filter image:')
3. Median filtered images have sharper outlines which emphasizes more detail in areas where sharp
transitions are present. The downside of using median filter is too much of it can cause salt and
pepper noise. For Averaging Filter, the intensity and shadows between pixels seemed more
distributed which causes a smoother image in total, resulting to an image with softer edges/lacks
sharpness.
4. %T5Q_GONZALES,MICHAELLA%
f = imread('flowers.tif');
fg = im2gray(f);
f = im2uint8(f(30:285, 60:315));
f = imnoise(f,'salt & pepper',0.05);
f_avg = imfilter(f,fspecial('average',3));
f_med = medfilt2(f);
f_out = f;
for i = 2:size(f,1)-1
for j = 2:size(f,2)-1
if f(i,j) == 0
f_out(i,j) = f(i-1,j-1);
elseif f(i,j) == 255
f_out(i,j) = f(i-1,j-1);
end
end
end
figure('Name', 'Raw');
imshow('flowers.tif');
title('Raw flowers.tif');
figure('Name', 'Sub-image');
imshow(fg);
title('Sub-image of flowers.tif');
figure('Name','Noise Reduction');
subplot(2,2,1),imshow(f),title('With salt and pepper noise');
subplot(2,2,2),imshow(f_avg),title('Averaging Filtering');
subplot(2,2,3),imshow(f_med),title('Median Filtering');
subplot(2,2,4),imshow(f_out),title('Outlier Method');
The outlier method is the best because it removes the noise without blurring the image.
5. %T5Q5_GONZALES,MICHAELLA%
f = imread('flowers.tif');
fg = im2gray(f);
f = im2uint8(f(30:285, 60:315));
f = imnoise(f,'salt & pepper',0.20);
f_med = medfilt2(f,[5 5]);
f_med1 = medfilt2(f,[3 3]);
f_med2 = medfilt2(f_med1,[3 3]);
figure('Name', 'Raw');
imshow('flowers.tif');
title('Raw flowers.tif');
figure('Name', 'Sub-image');
imshow(fg);
title('Sub-image of flowers.tif');
figure('Name','Noise Reduction');
subplot(2,2,1),imshow(f),title('With salt and pepper noise');
subplot(2,2,2),imshow(f_med),title('5 x 5 median filter');
subplot(2,2,3),imshow(f_med1),title('Two applications of a 3 x 3 median filter');
subplot(2,2,4),imshow(f_med2),title('Two applications of a 3 x 3 median filter');
The two applications of a 3 x 3 median filter produced a better result since the 5 x
5 median filter is too large and it removes too much detail while the 3 x 3 median
filter is small enough to remove the noise without doing such.
6. %T5Q6_GONZALES,MICHAELLA%
f = imread('flowers.tif');
fg = im2gray(f);
f = im2uint8(f(30:285, 60:315));
f1
f2
f3
f4
=
=
=
=
imnoise(f,'gaussian',0,0.01);
imnoise(f,'gaussian',0,0.02);
imnoise(f,'gaussian',0,0.05);
imnoise(f,'gaussian',0,0.1);
h = fspecial('average', 3);
f1_avg = imfilter(f1,h);
f2_avg = imfilter(f2,h);
f3_avg = imfilter(f3,h);
f4_avg = imfilter(f4,h);
f1_wiener
f2_wiener
f3_wiener
f4_wiener
=
=
=
=
wiener2(f1,[3
wiener2(f2,[3
wiener2(f3,[3
wiener2(f4,[3
3]);
3]);
3]);
3]);
figure('Name', 'Raw');
imshow('flowers.tif');
title('Raw flowers.tif');
figure('Name', 'Sub-image');
imshow(fg);
title('Sub-image of flowers.tif');
figure('Name','Noise Reduction');
subplot(2,2,1),imshow(f1),title('With Gaussian noise, mean = 0, variance = 0.01');
subplot(2,2,2),imshow(f1_avg),title('Average filtering');
subplot(2,2,3),imshow(f1_wiener),title('Wiener filtering');
figure('Name','Noise Reduction');
subplot(2,2,1),imshow(f2),title('With Gaussian noise, mean = 0, variance = 0.02');
subplot(2,2,2),imshow(f2_avg),title('Average filtering');
subplot(2,2,3),imshow(f2_wiener),title('Wiener filtering');
figure('Name','Noise Reduction');
subplot(2,2,1),imshow(f3),title('With Gaussian noise, mean = 0, variance = 0.05');
subplot(2,2,2),imshow(f3_avg),title('Average filtering');
subplot(2,2,3),imshow(f3_wiener),title('Wiener filtering');
figure('Name','Noise Reduction');
subplot(2,2,1),imshow(f4),title('With Gaussian noise, mean = 0, variance = 0.1');
subplot(2,2,2),imshow(f4_avg),title('Average filtering');
subplot(2,2,3),imshow(f4_wiener),title('Wiener filtering');
Last two images has high variance that equates to high noise that it makes it difficult for it to be
filtered.
IV. Assessment
Department
Subject Code
Description
Term/Academic Year
Computer Science
CSSSPEC8/CS0057
Image Processing using Matlab
Criteria
Uniqueness of code
Descriptions
Points
The code should not be same as others, it 25%
should be coded in the manner of how the
student code
Correctness of output
The script should be able to meet the 50%
expected output
Readability
Clarity of the written code, it should be 15%
readable
Completeness of submission
Submission should be complete
Total
10%
100%
Topic
Technical No
Lab Activity
CLO
Noise
5
Noise
1
Note: The following rubrics/metrics will be used to grade students’ output in the technical
assessment 5.
Download