One good strategy is to use a metric derived from the shape’s second–order (central) moments so that it is insensitive to image scale and in‐plane rotations but is sensitive to perspective (i.e. tilting) distortions.
For example, here’s one approach:
-
Compute the Object’s Centroid and Covariance Matrix:
Given the binary mask, calculate the centroid (mean pixel location) of the object. Then compute the covariance matrix (using the centered pixel coordinates) of the mask. In essence, you are looking at the distribution of the foreground pixels
[
C = \begin{pmatrix}
\sigma_{xx} & \sigma_{xy} \
\sigma_{xy} & \sigma_{yy}
\end{pmatrix}
]
where
- (\sigma_{xx} = \frac{1}{N}\sum (x_i - \bar{x})^2),
- (\sigma_{yy} = \frac{1}{N}\sum (y_i - \bar{y})^2),
- (\sigma_{xy} = \frac{1}{N}\sum (x_i - \bar{x})(y_i - \bar{y})).
-
Extract Rotation–Invariant Features:
Calculate the eigenvalues of the covariance matrix, say (\lambda_1) and (\lambda_2) (with, say, (\lambda_{\min}) and (\lambda_{\max})). These eigenvalues represent the variance along the principal axes. They are invariant to translation, scale (if you normalize appropriately) and 2D rotation. In a view where the camera is fronto–parallel, the apparent proportions of the object should match its “true” proportions. When the camera tilts, one of the principal directions is foreshortened, and the ratio between the eigenvalues changes.
-
Define the Metric:
A natural metric is the ratio
[
R = \frac{\lambda_{\min}}{\lambda_{\max}}.
]
– Invariance to Scale: The eigenvalue ratio is independent of absolute size.
– Invariance to 2D (In‐plane) Rotation: Because eigenvalues do not change if you rotate the data in the image plane.
– Sensitivity to Tilt: When the camera is tilted (left/right/up/down), one direction becomes foreshortened and the eigenvalue ratio will deviate from its fronto–parallel value.
-
Using the Metric:
– If you know the intrinsic (fronto–parallel) aspect ratio of your object (for instance, if it is square, rectangle, or ellipse with known proportions) then you can compare the measured ratio (R) of each image to the expected value.
– If your object is “ideally” symmetric (or you know its proper aspect ratio), then the image that yields an eigenvalue ratio closest to that value is the best candidate for a fronto–parallel view.
An alternative (but equivalent) approach is to fit an ellipse to the mask (using, for instance, least–squares) and then use the ellipse’s major and minor axis lengths. The ratio of the minor to major axis, or the ellipse’s eccentricity, will behave in the same way as described above.
Why This Works:
- In–plane rotations of the image do not change the eigenvalues of the covariance matrix (or the fitted ellipse’s axes).
- Scale does not affect the ratio because both eigenvalues change by the same factor.
- Any tilt of the camera will cause a foreshortening of one dimension of the shape, thereby changing the ratio.
Thus, by computing (R = \lambda_{\min} / \lambda_{\max}) (or the corresponding ratio from the ellipse fit) for each image, you can select the image that has a ratio closest to that of the object’s undistorted (fronto–parallel) view.
This approach meets all your criteria: sensitivity to tilt (camera left/right/up/down), insensitivity to in‐plane rotations and scale, and it uses only the binary segmentation from your images.