Find branches in a skeleton?

When you make a skeleton from a binary image you can extract branch points. However I m trying to find out which branch points are connected to which. I can find the index of the branch points. So I have a skeleton with labeled branch points and I can physically view the nodes that are connected to one another but I cannot seem to generate these connections in code? eg branch point 3 is connected to branch point 5.

6 Comments

it really would have helped if the bmorph(bw, 'branchpoints')function returned more information. Basically my guess is that because the branch points were found from a mask that just iterates through each pixel, it doesn't record the order of the branch connections.
Can you give the pixel layout where you'd have two branchpoints that are next to each other (connected to each other). If it was like a T then you'd have only one branchpoint in isolation - not touching any other branchpoint.
pic = imread('boo.bmp');
pic = rgb2gray(pic);
I = im2bw(pic);
BW3_skel = bwmorph(I,'skel',inf);
figure(1);
imshow(BW3_skel);
BW3_branchpoints = bwmorph(BW3_skel, 'branchpoints');
the_r = pic;
the_g = pic;
the_b = pic;
the_r(BW3_skel) = 255;
the_g(BW3_skel) = 0;
the_b(BW3_skel) = 255;
the_out = cat(3,the_r,the_g,the_b);
figure(2)
imshow(the_out);
[node_x,node_y] = find(BW3_branchpoints == 1);
hold on
%imshow(myImage);
nodes = [(1:length_node_x); the_nodes]';
plot(nodes(:,2), nodes(:,3),'b.');
length_node_x = length(node_x);
the_nodes = zeros(2,length_node_x);
the_nodes(1,1:end) = node_y(1:end);
the_nodes(2,1:end) = node_x(1:end);
for s = 1:length_node_x
text(nodes(s,2),nodes(s,3),[' ' num2str(s)], 'Color', 'r');
%plot(nodes(segments(s,2:3)',2),nodes(segments(s,2:3)',3),'c');
end
disp(nodes);
The out put of the nodes is in the format [index, x, y].
I have also attached the two outputs from the code that displays the skeleton image with the labeled nodes.
1 2 245
2 4 2
3 25 119
4 60 119
5 70 2
6 71 11
7 132 128
8 139 230
9 143 17
10 320 12
Hi, I tried running this code..it gave me below error - Error using fopen File name must be a vector of type char.
Error in isdicom (line 9) fid = fopen(filename, 'r');
Error in images.internal.getImageFromFile (line 44) if (isdicom(filename))
Error in images.internal.imageDisplayParseInputs (line 74) images.internal.getImageFromFile(common_args.Filename);
Error in imshow (line 222) images.internal.imageDisplayParseInputs({'Parent','Border','Reduce'},preparsed_varargin{:});
Error in Preprocess (line 52) imshow(the_out);
karishma singh: which code was it that you ran? None of the code that is posted in this Question calls Preprocess or defines a variable named the_out ?
Preprocess.m is just my file name. I ran the code posted by Ronan using my skeleton image.

Sign in to comment.

Answers (1)

Image Analyst
Image Analyst on 15 Sep 2015
I think you'll need to get an image of just the branch points. Then an image of just the branches with the branchpoints removed. Then pick two branchpoints to test and make an image with just those two. Then put in each branch one at a time and call bwdistgeodesic() to see if they're connected by that branch.

1 Comment

I was hoping to do it without the bwdistgeodesic function because my version of matlab doesn't have that function. I was thinking of trying to traverse the skeleton path and while traversing keep checking if the skeleton pixel is one of the nodes. It would probably involve a mask for checking if adjacent pixels are the skeleton however this solution is tricky and maybe computationally expensive. also it seems like reinventing the wheel because thats how some of the bwmorph operations work. Do you know is there an open source or alternative version to bwdistgeodesic?

Sign in to comment.

Asked:

on 15 Sep 2015

Commented:

on 8 Aug 2017

Community Treasure Hunt

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

Start Hunting!