%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

 채택된 답변

Walter Roberson
Walter Roberson 2014년 3월 17일

0 개 추천

For the N x N, use
x = (1:N).';
y = x;

댓글 수: 3

Jensen
Jensen 2014년 3월 17일
편집: Jensen 2014년 3월 17일
Is it that i only need to change
x=[1:3]'; y=[1:3]';
into x = (1:N).'; y = x; ??
When i change it. The coding got error :
|??? Index exceeds matrix dimensions.
Error in ==> Untitled at 20
window=reshape(modifyA(i+x-1,j+y-1),[],1);|
The code has size(modifyA,1)-2 in the for loop. Change that -2 to -N+1 where N is a variable holding the desired size. Make the same kind of change on the following line.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Andrei Bobrov
Andrei Bobrov 2014년 3월 17일

0 개 추천

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

Jensen
Jensen 2014년 3월 17일
편집: Jensen 2014년 3월 17일
I am kinda new in this Matlab coding. Can u teach how to use imdilate from Image Prcessing Toolbox ? Is it i just at it onto the code ?
Andrei Bobrov
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
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

댓글을 달려면 로그인하십시오.

질문:

2014년 3월 17일

댓글:

2014년 3월 17일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by