Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Eliminate the possibility of the perspective transform collapsing #1489

Merged
merged 1 commit into from
Nov 5, 2023

Conversation

alicangok
Copy link
Contributor

@alicangok alicangok commented Oct 25, 2023

Prior to this change, while the perspective transform could collapse at any selection of the scale parameter, it was especially more prevelant for higher values of scale. Specifically, the randomly generated transformation polygon had a non-zero chance of being concave, which led to collapsed perspective transformations.

A more refined (and easier to understand) solution requires the implementation of "Concave Polygon Recoverer" like in imgaug. That being said, simply restricting the randomly generated points values to the range [0, 1/3] ensures geometrically that the generated polygon will be convex, hence resulting in a valid (uncollapsed) perspective transformation.

In the code, I set the upper limit at 0.32 instead of 1/3, to avoid any potential numerical issues (due to near-concave polygons), with the same motivation behind the piece of code ensuring that min_height and min_width are over 2.0, shortly following the polygon generation.

Fixes #1001

Prior to this change, while the perspective transform could collapse at any selection of the scale parameter, it was especially more prevelant for higher values of scale. Specifically, the randomly generated transformation polygon had a non-zero chance of concave, which led to collapsed perspective transformations.

A more refined (and easier to understand) solution requires the implementation of "Concave Polygon Recoverer" like in imgaug. However, restricting the randomly generated `points` values [0, 1/3] ensures geometrically that the generated polygon will be convex, hence resulting in a valid (uncollapsed) perspective transformation.

The upper limit is set to 0.32 instead of 1/3, to avoid any potential numerical issues (due to near-concave polygons), with the same motivation behind the piece of code ensuring that `min_height` and `max_height` are over 2.0, shortly following the polygon generation.
@alicangok
Copy link
Contributor Author

image

@Dipet Dipet merged commit a919a77 into albumentations-team:master Nov 5, 2023
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Undefined behaviour of albumentations.Perspective()
2 participants