Gripper aligned to the long direction of a diagonal silver connecting rod.

What you need

Use a clean mask of one elongated part and a numerical array library. Visualize results on saved images.

Shape anisotropy examples. Elongated part: 16 eigenvalue ratio; Nearly round part: 1.1 eigenvalue ratio.
Shape anisotropy examples. Original Academy diagram using illustrative values; not a measured hardware result.
Read the diagram as a data table
Values used in the illustration
Condition or componenteigenvalue ratio
Elongated part16
Nearly round part1.1

The calculation

θ = atan2(v_y, v_x)
r_shape = λ_max / λ_min

v is the dominant covariance eigenvector. Eigenvalues describe spread in pixel²; the ratio is undefined if the minor eigenvalue is zero.

Worked example

Illustrative numbers. Replace them with your measured inputs.

A dominant vector (0.866, 0.5) gives 30°. Eigenvalues 400 and 25 yield a ratio of 16, suggesting strong elongation. Values 110 and 100 yield only 1.1, making a stable orientation much harder to infer.

Try it step by step

  1. Extract foreground coordinates from one valid component and subtract their mean before computing covariance.
  2. Find the eigenvector associated with the largest eigenvalue and overlay the axis through the centroid.
  3. Define the 180° ambiguity explicitly; a symmetric part’s main axis does not identify which end is which.
  4. Reject near-round or poorly segmented cases and validate orientation error against manually checked reference images.

How to check the result

Test rotations across the full required angle range and confirm the reported direction is continuous under your chosen angle convention.

Common mistake to avoid

Image y commonly points downward. Mixing image and robot angle conventions can reverse the commanded rotation.

Reference reading

Primary references for the underlying models, APIs or application context. The worked numbers and plots above are educational calculations, not results reported by these sources.

Read our methods, limitations and safety notes.