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

2 次查看(过去 30 天)
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 中查找有关 Image Segmentation and Analysis 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by