Max filter for 5 x 5 and 9 x 9 pixel size
Show older comments
%READ AN IMAGE
A = imread('sample2.jpg');
A = rgb2gray(A(1:300,1:300,:));
figure,imshow(A),title('ORIGINAL IMAGE');
%PREALLOCATE THE OUTPUT MATRIX
B=zeros(size(A));
%PAD THE MATRIX A WITH ZEROS
modifyA=padarray(A,[1 1]);
x=[1:3]';
y=[1:3]';
for i= 1:size(modifyA,1)-2
for j=1:size(modifyA,2)-2
%VECTORIZED METHOD
window=reshape(modifyA(i+x-1,j+y-1),[],1);
%FIND THE MAXIMUM VALUE IN THE SELECTED WINDOW
B(i,j)=max(window);
end
end
%CONVERT THE OUTPUT MATRIX TO 0-255 RANGE IMAGE TYPE
B=uint8(B);
figure,imshow(B),title('IMAGE AFTER MAX FILTERING');
I want to do a 5x5 and 9x9 size pixel fro this coding. Can someone help me ?
Thank you
Accepted Answer
More Answers (1)
Andrei Bobrov
on 17 Mar 2014
In your case use function imdilate from Image Processing Toolbox,
for 5x5:
B = imdilate(A,ones(5));
for 9x9:
B = imdilate(A,ones(9));
3 Comments
Andrei Bobrov
on 17 Mar 2014
Edited: Andrei Bobrov
on 17 Mar 2014
You must be install Image Processing Toolbox (if it is not installed) and run following:
A = imread('sample2.jpg');
A = rgb2gray(A(1:300,1:300,:));
figure,imshow(A),title('ORIGINAL IMAGE');
B = imdilate(A,ones(5));
B=uint8(B);
figure,imshow(B),title('IMAGE AFTER MAX FILTERING');
Image Analyst
on 17 Mar 2014
It looks like it may be a homework assignment since I just answered this yesterday for someone else: http://www.mathworks.com/matlabcentral/answers/121748#answer_128654
Categories
Find more on Image Filtering in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!