Identify neighbours in image after finding regionprops centroids
2 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
采纳的回答
Matt J
2022-3-19
编辑:Matt J
2022-3-19
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)
0 个评论
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!