how to find max neighbour pixel in a 8-cordinated window?

조회 수: 1 (최근 30일)
sheno39
sheno39 2013년 10월 8일
답변: Sean de Wolski 2013년 10월 8일
i have made a code.. it is not working properly. i need to find maximum neighbour pixel for each pixels by considering only its neighbor pixels(i.e.) surounding 8 pixels.In my code it takes 9 pixels. how to correct my code? can anyone help me.
I=[2 3 10 4 6; 1 4 7 5 3; 5 2 8 4 3;8 2 1 7 3;1 9 8 3 4;];
D = padarray(I,[1 1],0,'both');
[x y]=size(D);
m=1;
n=1;
for i=2:x-1
for j=2:y-1
I1(m,n)=max(max(D(i-1:i+1,j-1:j+1)));
n=n+1;
end
m=m+1;
n=1;
end
I1=I1(1:x-2,1:y-2);
size(D)
size(I1)

답변 (1개)

Sean de Wolski
Sean de Wolski 2013년 10월 8일
Extract the neighborhood into its own variable and set the middle value to -inf

카테고리

Help CenterFile Exchange에서 Statistics and Machine Learning Toolbox에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by