6
votes

Having centroids of superpixels for an image, is there any MATLAB function for drawing region adjacency graph ?

  L = superpixels(A, 200);
  K=regionprops(L, 'Centroid');  % Detemining centroid coordinates of each superpixels

Centroid coordinates Desired Output

P.S. Similar but not exact solutions :

https://www.mathworks.com/matlabcentral/fileexchange/16938-region-adjacency-graph-rag

https://www.mathworks.com/matlabcentral/fileexchange/53614-image-graphs

1
The red lines are the outlines of the superpixels, the green lines connect all neighboring superpixels, which can be determined as in your other question. The answer there shows you how to construct this graph. I'm not sure what you are asking for here that is not already given there. Are you asking how to draw the graph over the image? - Cris Luengo
@CrisLuengo, In fact, I'm wondering how to draw the graph! - dtr43
You have the centroids, and you have a list of neighbors. Iterate through the list, and for each pair, find the centroid of the two neighbors, draw a line from the one to the other. Please indicate which step here you are having trouble with. - Cris Luengo
Instead of trying to get attention by making trivial edits, you could answer my question above. I’m trying to help, but I don’t like doing all your work for you, I’m more interested in helping you over a hump. I think most other people here feel the same way. - Cris Luengo

1 Answers

4
votes

There are a huge amount of ways of generating graphs from nodes, and you have not specified which one you want.

One that resembles the image you provided (but its not the same) would be triangulating the domain with delaunay(). You can generate a triangulation() object from that, which contains more usable information than the output of delaunay

Alternatively, if you have your own criteria for connecting the nodes that you decided not to share, you can use graph() to generate any topology of graphs.

If you have it in a triangulation format, plotting it can be done with triplot(), trimesh() or some others. With a hold on and triplot() you will find the closest to the figure you posted.

If you want working code I am happy to provide if you add a runnable snippet in the question.