I try to write script which would calculate the angle between two segments.
Here is the image I have
I obtained the segments using simple threshold
Then I would need to draw (automatically by python script as it is a part of an extension) lines through the segments and calculate the angle between the two lines.
As part of the extension I already have the center coordinates of the segments.
Get two points (e.g. along axis of symmetry) from each segment. Two points gives you a vector for each segment. Calculate cross or dot product of that vectors, that gives you either sine or cosine value of the angle.
The problem is how to calculate two points along axis of symmetry, or something like that? If the task is not on the plane, then you need three points.
I would consider using Principal Component Analysis, specifically the sklearn implementation.
Form an n-by-2 matrix of points in image space, either taking the positions of all points in one segment, or all points on the boundary of a segment (experiment to find which works better for you). Call this matrix X.
Use sklearn.decomposition.PCA().fit(X).components_ to get the first principal component. This should be a 2-vector that points along the length of the segment.
Measure the angles between these orientation vectors.
Segment Statistics module solves this very nicely: it can compute oriented bounding box and principal axes directions for each segment, directly from the segmentation.