Max filter for 5 x 5 and 9 x 9 pixel size
이전 댓글 표시
%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
채택된 답변
추가 답변 (1개)
Andrei Bobrov
2014년 3월 17일
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
Andrei Bobrov
2014년 3월 17일
편집: Andrei Bobrov
2014년 3월 17일
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
2014년 3월 17일
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
카테고리
도움말 센터 및 File Exchange에서 Image Filtering에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!