How I find 8-connectivity of a binary image like [1 0 0 0 ;0 1 0 0;0 0 1 0;0 0 0 1] with gry level 1..in matlab... I want to make code program in matlab

1 次查看(过去 30 天)
How I find 8-connectivity of a binary image like [1 0 0 0 ;0 1 0 0;0 0 1 0;0 0 0 1] with gry level 1..in matlab... I want to make code program in matlab
  2 个评论
Maher Mehro
Maher Mehro 2020-2-19
1 1 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 1 0 0 0 0 1 this is ka matrix with p=(1,1)and q=(5,5) and v={1} if there exist path between p and q... How I make code for checking connectivity between them.. Step by step... 4-connectivity 8-connectivity and m-connectivity..

请先登录,再进行评论。

回答(1 个)

Image Analyst
Image Analyst 2020-2-22
Check the label:
[labeledImage, numberOfBlobs] = bwlabel(binaryImage, 8); % Label with 8-connectivity
if labeledImage(1,1) == labeledImage(5,5)
% They're the same label so there is a path connecting them.
uiwait(msgbox('Those points are connected.'))
else
% They're NOT the same label so there is NO path connecting them.
uiwait(msgbox('Those points are NOT connected.'))
end
%=================================================================================================
% Now the same but with 4-connectivity.
[labeledImage, numberOfBlobs] = bwlabel(binaryImage, 4); % Label with 4-connectivity
if labeledImage(1,1) == labeledImage(5,5)
% They're the same label so there is a path connecting them.
uiwait(msgbox('Those points are connected.'))
else
% They're NOT the same label so there is NO path connecting them.
uiwait(msgbox('Those points are NOT connected.'))
end
For "m" connectivity, you might have to write your own special labeling routine. I've never heard of this being needed. Why do you need it?

标签

尚未输入任何标签。

Community Treasure Hunt

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

Start Hunting!

Translated by