MATLAB: How to find the centroids and the angle between each of them

image processing

Hi i found the centroids of the each white regions using regionprops. How can i find the distance and angle between each centroids and mark the points which are almost in straight line?

Best Answer

Once you know the centroids as x-y coordinates, it is easy to find their distances and angles. Suppose A = [x1,y1], B = [x2,y2], and C = [x3.y3] are three centroid positions.
For example, the distance between A and B is:
distAB = sqrt((x2-x1)^2+(y2-y1)^2);
and the interior angle in triangle ABC at centroid B is:
angB = atan2(abs((x1-x2)*(y3-y2)-(x3-x2)*(y1-y2)),...
(x1-x2)*(x3-x2)+(y1-y2)*(y3-y2));
Related Question