Know which branchpoints are connected to other branchpoints?
5 ビュー (過去 30 日間)
古いコメントを表示
If I get a skeleton of a binary image and return the branchpoints I want to know which ones are connected to which. eg if I have 5 branchpoints and branchpoint 2 is connected to branchpoint 4, how would I know this?
0 件のコメント
回答 (1 件)
DGM
2024 年 10 月 12 日
There are probably smarter ways to do it, but:
% a logical image
inpict = imread('hands1-mask.png');
% the skeleton
sk = bwskel(inpict);
imshow(sk)
% i'm just going to consider all nodes
% i.e. both branchpoints and endpoints
bp = bwmorph(sk,'branchpoints');
ep = bwmorph(sk,'endpoints');
N = bp | ep;
% dilate to make sure 8-connectivity is broken
N = bwmorph(N,'dilate');
% the edges alone
E = sk & ~N;
% form label arrays
[Le numedges] = bwlabel(E,8); % for addressing
[Ln numnodes] = bwlabel(N,8); % for sampling
% find connectivity list
connectednodes = zeros(numedges,2);
for ke = 1:numedges
% create a mask and sample the node label array
thismk = bwareafilt((Le == ke) | N,1);
connectednodes(ke,:) = nonzeros(unique(Ln(thismk)));
end
% summarize
edgelist = (1:numedges).';
nodelist = (1:numnodes).';
table(edgelist,connectednodes)
I'm sure any other information can be figured out from there.
% we can still figure out what the neighbors are
neighbornodes = cell(numnodes,1);
for k = 1:numnodes
mk = connectednodes == k;
mk = any(mk,2) & ~mk; % exclude self-connection
neighbornodes{k} = connectednodes(mk).';
end
table(nodelist,neighbornodes)
This can probably be broken if nodes are too close to each other (<3px or so). At that point, the dilation eliminates the interconnecting edge.
0 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!