I have a binary image whose foreground is white. From the branch points and end points of its axial axial coordinate, I would like to build a graph. Ideally, with the following structure:
- [nodes] having the format [ID XY], where X, Y are the pixel locations of the branch points or end points, and ID is the node identifier is an integer.
- [edge], which has the format [ID N1 N2], where N1 and N1 represent node identifiers.
Using both [nodes] and [edges], I will map the skeleton to an undirected representation of the graph.
In the code below, I can calculate the branch and end points, but now I need to connect them correctly:
skelImg = bwmorph(im, 'thin', 'inf'); branchImg = bwmorph(skelImg, 'branchpoints'); endImg = bwmorph(skelImg, 'endpoints'); [row, column] = find(endImg); endPts = [row column]; [row, column] = find(branchImg); branchPts = [row column]; figure; imshow(skelImg); hold on; plot(branchPts(:,2),branchPts(:,1),'r*'); hold on; plot(endPts(:,2),endPts(:,1),'*');
The following is an example of the input image (left), its skeleton (middle) and the corresponding branches and end points (right):



Or also in full resolution at the following URL: http://imgur.com/a/a3s4F/
source share