Identify neighbours in image after finding regionprops centroids

2 views (last 30 days)
I have an example image with different RGB color values. I have used ColorThresholder to create a mask to get every different RGB color and then used regionprops (extrema and centroid) to get the corner points and centroids of each shape. I would now like to calculate the distance between neighbouring centroids and corner points. In other words, I would like to store the data in such a way that it is clear that the yellow and green squares are connected to the black one and that I can thereby easily calculate the distance between those centroids. What is the best way to store the data after using regionprops to be able to achieve this?
Any help or suggestion will be appreciated.

Accepted Answer

Matt J
Matt J on 19 Mar 2022
Edited: Matt J on 19 Mar 2022
I would create a polyshape for each of the regions based on the extrema that you found. You can dtermine whether 2 polyshapes p_i and p_j border each other with,
P=intersect(polybuffer([p_i,p_j],smallnumber));
A(i,j) = (P.NumRegions>0)
Once you've done that for all pairs of regions i and j, you will have an adjacency matrix A which you can then use to build a graph object describing the region connectivity,
G=graph(A)

More Answers (0)

Community Treasure Hunt

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

Start Hunting!