Is there any way to check whether two pixels in a binary image are connected, if connected, it will return TRUE else FALSE.....???

6 次查看(过去 30 天)
Based on connectivity or whether two pixels in another image ( Image 1 ) are connected, I have to draw line between those pixels in another image (Image 2).? Remember Image 2 carries interest points (branch,end,start, and another important points) of image 1.Any suggestion..?

采纳的回答

Image Analyst
Image Analyst 2018-7-19
If you simply want to see if they're connected, use bwlabel() to do connected component labelling on them, and then check for the same label value (meaning they're part of the same connected region):
[labeledImage, numberOfRegions] = bwlabel(binaryImage);
if labeledImage(row1, col1) == labeledImage(row2, col2)
% They're connected.
end
Calling bwdistgeodesic() or regionprops() will give you the pixels connecting them.
bwdistgeodesic() will give you the shortest path. See Steve's blog: http://blogs.mathworks.com/steve/2011/11/01/exploring-shortest-paths-part-1/.
Whereas regionprops() (or find() after using ismember() to extract the region you want) will give you ALL the pixels in the region.
  2 个评论
Mohammad Bhat
Mohammad Bhat 2018-7-21
编辑:Mohammad Bhat 2018-7-21
Sir, I got the desired coordinates to whom I have to now connect edges or form an Adjacency matrix..how can I do that...
Mohammad Bhat
Mohammad Bhat 2018-7-21
A=kl_thin; % Skeletionised Image
B = rgb_final; % key_points taken from skeleton Image
[r,c]=find(B==1); % Finding coordinates of Key_points
rc=[r,c];
[labeledImage, numberOfRegions] = bwlabel(A); % labeling pixels in skeletal
% Image i.e., in A
k=1;
for i=1:length(rc)
for j=i+1:length(rc)
if labeledImage(rc(i,1), rc(i,2)) == labeledImage(rc(j,1), rc(j,2)) % checking their respective labels
h1=sub2ind(size(kl_thin),rc(i,1), rc(i,2)); % if connected extract respective Linear Indices
h2=sub2ind(size(kl_thin),rc(j,1), rc(j,2));
Edges(k,:)=[h1 h2]; % build a edge list
k=k+1;
end
end
end
Now, Problem is When I am building Adjacency Matrix, I am not getting the desired graph that will connect each key_point (acts as nodes) when they are connected in skeletal Image i.e., In Image B. How to do achieve the desired graph...

请先登录,再进行评论。

更多回答(2 个)

Walter Roberson
Walter Roberson 2017-11-23
You can use the (BW, R, C) form, where R and C are row and column of one of the two endpoints to be queried. Index the result of the function at the other endpoint. If the result there is infinity then there is no connection.
  5 个评论
Walter Roberson
Walter Roberson 2017-11-23
L = imclearborder(im2bw(imread('lllllll.jpg')));
H = imclearborder(im2bw(imread('hhhhh.jpg')));
Lpos = find(L);
HLab = bwlabel(H);
LLab = HLab(Lpos);
[LRow, LCol] = ind2sub(size(L), Lpos);
LLab is the same for all pixels that were originally part of the same component.
groups = accumarray(LLab, (1:length(LLab)).', [], @(x) {x});
now groups is a cell array of groupings. The values in any one groups{K} are indices into Lpos, the linear indices of the representative pixels in L. Perhaps you might prefer
groupsLidx = accumarray(LLab, Lpos, [], @(x) {x});
in which for any given groupsLidx{K} all of the members are linear indices of individual pixels.
Or perhaps,
LLimg = zeros(size(HLab));
LLimg(Lpos) = HLab(Lpos);
and now LLimg(R1, C1) and LLimg(R2, C2) are part of the same original component in H if they have the same value.
Mohammad Bhat
Mohammad Bhat 2018-7-19
编辑:Mohammad Bhat 2018-7-19
Sir ,I tried it but not working, need further help , here are my images, if possible kindly give me some
code:-
I have to connect each pair of nodes in image 2 , whenever they are directly connected in image 1 such
that Image 3 will result..

请先登录,再进行评论。


Mohammad Bhat
Mohammad Bhat 2017-11-23
This is my image after I extracted important image from above original image...

Community Treasure Hunt

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

Start Hunting!

Translated by