Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Graph from medial axis skeleton

I've a binary image whose foreground is white. Out of the branchpoints and endpoints of its medial-axis skeleton, I would like to build a graph. Ideally, with the following structure:

  1. [nodes] having the format [ID X Y] where X,Y are the pixel locations of the branchpoints or endpoints, and ID is the node's ID - an integer number.
  2. [edges] having the format [ID N1 N2] where N1 and N1 represent the node's IDs.

By using both [nodes] and [edges] I'll have then a mapping of the skeleton into an undirected graph representation.

With the code below, I can compute the branch and endpoints, but now I need to connect them properly:

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),'*');

An example of the input image (on the left), its skeleton (middle), and the corresponding branch- and end-points (right) is given below:

Or also in full resolution in the following url: http://imgur.com/a/a3s4F/

like image 756
Tin Avatar asked Oct 19 '12 10:10

Tin


People also ask

What is the drawing away from the medial axis of the body?

Lateral – Away from the medial line or central axis of the body.

How do you find medial axis?

The medial axis is calculated as follows: at first, reconstructing bitmap image from contour information, then, thinning the bitmap image, finally, creating the line segment information of the resulting skeleton. Now. the medial axis shows a broad shape of the target.

What is medial axis transform?

Medial Axis Transform (MAT) is a representation that encodes an object with symmetric (medial) axes in the object interior. MAT has been employed in a variety of applications such as pattern recognition of digital images, biological shape analysis and robotic motion planning.

What is medial axis of an object?

The medial axis of an object is the set of all points having more than one closest point on the object's boundary. Originally referred to as the topological skeleton, it was introduced in 1967 by Harry Blum as a tool for biological shape recognition.


2 Answers

As the first step, I suggest using BFS variant. You nodes are white pixels, and there is an edge if the two pixels are neighbors. This will provide you a full graph with unneeded nodes, the points that are not branch-points/end-points.

Now, here is an important observation, each of the unneeded nodes contains exactly 2 edges, otherwise it would have been a branch-point or an end-point.

Thus, start removing all unneeded nodes recursively:

While there are nodes that are not branchpoints/endpoints
    Select one of these nodes.
    Merge its two edges into one by removing the node.
like image 182
Andrey Rubshtein Avatar answered Oct 19 '22 22:10

Andrey Rubshtein


A possible solution consists in:

getting branched points (bp) from skeleton
getting edges : edges=skeleton-bp
getting end points from edges
adding branched points in a graph
getting endpoints neighbouring branched points and linking
adding remaining endpoints in the graph
linking endpoints

A python implementation with networkx yields: from skeleton of B to graph

like image 30
Jean-Pat Avatar answered Oct 20 '22 00:10

Jean-Pat