5

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

dtr43
  • 135
  • 7
  • 19
  • 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](https://stackoverflow.com/q/54959824/7328782). 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 Mar 15 '19 at 13:42
  • @CrisLuengo, In fact, I'm wondering how to draw the graph! – dtr43 Mar 18 '19 at 14:45
  • 1
    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 Mar 18 '19 at 16:22
  • 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 Mar 19 '19 at 13:45

1 Answers1

4

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.

Ander Biguri
  • 35,140
  • 11
  • 74
  • 120
  • 1
    The desired image is updated. The current version can represent the requirement in most appropriate way. Does it affect the answer(suggested function)? – dtr43 Mar 12 '19 at 17:46
  • 1
    @dtr43 that looks like a delaunay triangulation, but its impossible to say without mathematical proof. It is just the most common trianuglation, so it would make sense – Ander Biguri Mar 12 '19 at 23:16
  • 1
    They already have [a way to construct the graph](https://stackoverflow.com/q/54959824/7328782), I think the question might be about how to draw the graph? – Cris Luengo Mar 15 '19 at 13:48
  • @CrisLuengo who knows. They say "constructing" twice, so I answered that – Ander Biguri Mar 15 '19 at 15:03
  • @CrisLuengo & Ander , Cris is right! In fact I want to find a way to draw such a graph. – dtr43 Mar 16 '19 at 15:08