Question

Perform 3x3, 5x5 and 11x11 average filtering of the noisy the image in ImageSet3 ( image attached...

Perform 3x3, 5x5 and 11x11 average filtering of the noisy the image in ImageSet3 ( image attached below). Do median filtering on the same data using 3x3,5x5 and 11x11 kernels. Compare your results.

You may use the matlab built-in functions/library to expedite your work

0 0
Add a comment Improve this question Transcribed image text
Answer #1

3*3 Average Filtering:

windowSize = 3; % Whatever odd number you want. Larger = more blur.
kernel = ones(windowSize) / windowSize ^ 2 ;
y = imread('ImageSet3.png');
blurredImage = conv2(single(y), kernel, 'same');
imshow(blurredImage, []); % or imshow(uint8(blurredImage), [0 255]);

3*3 Averaged image:

:

5*5 Average Filtering:

windowSize = 5; % Whatever odd number you want. Larger = more blur.
kernel = ones(windowSize) / windowSize ^ 2 ;
y = imread('ImageSet3.png');
blurredImage = conv2(single(y), kernel, 'same');
imshow(blurredImage, []); % or imshow(uint8(blurredImage), [0 255]);

5*5 averaged image:

11*11 Average Filtering:

windowSize = 11; % Whatever odd number you want. Larger = more blur.
kernel = ones(windowSize) / windowSize ^ 2 ;
y = imread('ImageSet3.png');
blurredImage = conv2(single(y), kernel, 'same');
imshow(blurredImage, []); % or imshow(uint8(blurredImage), [0 255]);

11*11 averaged image:

3*3 Median Filtering:


I = imread('ImageSet3.png'); % Reading an Image
display(size(I)); %Shows the Size of read Image

figure,imshow(I);title('Grayscale Image'); %Shows the read Image


%DEFINE THE WINDOW SIZE MXN
M=3;
N=3;

%PAD THE MATRIX WITH ZEROS ON ALL SIDES
modifyA=padarray(I,[floor(M/2),floor(N/2)]); %%padarray is a builtin matlab
%%function to pad zeros and floor function rounds the number to negative infinite, as M=3
%%N =3 , M/2 = N/2 = 1.5 which when floor applied to them gives 1 as
%%floor(1.5) is 1. So kernel matrix size is 1*1, so 0 is padded to the
%%image
figure,imshow(uint8(modifyA)); title('PADDED WITH ZEROS'); %This is the Zero Paddedimage

%%Median is the middle point of the series. The index that is obtained by dividing the total number of elements in a window by 2 gives the position.
B = zeros([size(I,1) size(I,2)]);
med_indx = round((M*N)/2); %MEDIAN INDEX

%%A sliding window of size M x N is used and the elements in the window are sorted and the middle element from the sorted array is chosen.
for i=1:size(modifyA,1)-(M-1)
for j=1:size(modifyA,2)-(N-1)


temp=modifyA(i:i+(M-1),j:j+(N-1),:);
tmp_sort = sort(temp(:));%tmp(:) converts 2D matrix to 1D matrix
B(i,j) = tmp_sort(med_indx);
  
  

end
end


%CONVERT THE IMAGE TO UINT8 FORMAT.
B=uint8(B);
figure,imshow(B);
title('IMAGE AFTER MEDIAN FILTERING');

3*3 Median Filtered Image:

IMAGE AFTER MEDIAN FILTERING

5*5 Median Filtering:

I = imread('ImageSet3.png');
display(size(I));

figure,imshow(I);title('Grayscale Image');


%DEFINE THE WINDOW SIZE MXN
M=5;
N=5;

%PAD THE MATRIX WITH ZEROS ON ALL SIDES
modifyA=padarray(I,[floor(M/2),floor(N/2)]);
%%padarray is a builtin matlab
%%function to pad zeros and floor function rounds the number to negative infinite, as M=3
%%N =5 , M/2 = N/2 = 2.5 which when floor applied to them gives 1 as
%%floor(2.5) is 2. So kernel matrix size is 2*2, so zero matrix of size 2*2 is padded to the
%%image
figure,imshow(uint8(modifyA)); title('PADDED WITH ZEROS');


%%Median is the middle point of the series. The index that is obtained by dividing the total number of elements in a window by 2 gives the position.
B = zeros([size(I,1) size(I,2)]);
med_indx = round((M*N)/2); %MEDIAN INDEX
%%A sliding window of size M x N is used and the elements in the window are sorted and the middle element from the sorted array is chosen.
for i=1:size(modifyA,1)-(M-1)
for j=1:size(modifyA,2)-(N-1)


temp=modifyA(i:i+(M-1),j:j+(N-1),:);
tmp_sort = sort(temp(:));%tmp(:) converts 2D matrix to 1D matrix
B(i,j) = tmp_sort(med_indx);
  
  

end
end


%CONVERT THE IMAGE TO UINT8 FORMAT.
B=uint8(B);
figure,imshow(B);
title('IMAGE AFTER MEDIAN FILTERING');

5*5 Median Filtered Image:

IMAGE AFTER MEDIAN FILTERING

11*11 Median Filtering:

I = imread('ImageSet3.png');
display(size(I));

figure,imshow(I);title('Grayscale Image');


%DEFINE THE WINDOW SIZE MXN
M=11;
N=11;

%PAD THE MATRIX WITH ZEROS ON ALL SIDES
modifyA=padarray(I,[floor(M/2),floor(N/2)]);
%%padarray is a builtin matlab
%%function to pad zeros and floor function rounds the number to negative infinite, as M=3
%%N =5 , M/2 = N/2 = 2.5 which when floor applied to them gives 1 as
%%floor(2.5) is 2. So kernel matrix size is 2*2, so zero matrix of size 2*2 is padded to the
%%image
figure,imshow(uint8(modifyA)); title('PADDED WITH ZEROS');


%%Median is the middle point of the series. The index that is obtained by dividing the total number of elements in a window by 2 gives the position.
B = zeros([size(I,1) size(I,2)]);
med_indx = round((M*N)/2); %MEDIAN INDEX
%%A sliding window of size M x N is used and the elements in the window are sorted and the middle element from the sorted array is chosen.
for i=1:size(modifyA,1)-(M-1)
for j=1:size(modifyA,2)-(N-1)


temp=modifyA(i:i+(M-1),j:j+(N-1),:);
tmp_sort = sort(temp(:));%tmp(:) converts 2D matrix to 1D matrix
B(i,j) = tmp_sort(med_indx);
  
  

end
end


%CONVERT THE IMAGE TO UINT8 FORMAT.
B=uint8(B);
figure,imshow(B);
title('IMAGE AFTER MEDIAN FILTERING');

11*11 Median Filtered Image:

IMAGE AFTER MEDIAN FILTERING

Add a comment
Know the answer?
Add Answer to:
Perform 3x3, 5x5 and 11x11 average filtering of the noisy the image in ImageSet3 ( image attached...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT