Skip to content

Add 'crop' option to RandomRotation#9458

Open
sg3-141-592 wants to merge 1 commit intopytorch:mainfrom
sg3-141-592:randomrotate-cropping
Open

Add 'crop' option to RandomRotation#9458
sg3-141-592 wants to merge 1 commit intopytorch:mainfrom
sg3-141-592:randomrotate-cropping

Conversation

@sg3-141-592
Copy link
Copy Markdown
Contributor

@sg3-141-592 sg3-141-592 commented Mar 29, 2026

Add 'crop' option to RandomRotation that centre crops the rotated image to remove any padding regions introduced by the rotation #9147

image

crop and expand are mutually exlusive.

This is based off the approach in albumentations - rotate.py. Which in turn is taken from here https://stackoverflow.com/questions/16702966/rotate-image-and-crop-out-black-borders. Slight difference is we use int() (floor) for the final crop dimensions rather than Albumentations' coordinate-based rounding, to guarantee no fill pixels appear in the output.

I've added a RandomRotation._extract_params_for_v1_transform override to strip the crop parameter for torch.jit.script() compatibility, and to raise a ValueError if crop=True since the v1 transform has no equivalent.

@pytorch-bot
Copy link
Copy Markdown

pytorch-bot bot commented Mar 29, 2026

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/vision/9458

Note: Links to docs will display an error until the docs builds have been completed.

❌ 3 New Failures

As of commit 87ef6ab with merge base 6676c01 (image):

NEW FAILURES - The following jobs have failed:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@meta-cla meta-cla bot added the cla signed label Mar 29, 2026
@sg3-141-592 sg3-141-592 marked this pull request as draft March 29, 2026 14:39
@sg3-141-592 sg3-141-592 force-pushed the randomrotate-cropping branch from dc34375 to db55653 Compare March 29, 2026 15:14
…ve any padding regions introduced by the rotation
@sg3-141-592 sg3-141-592 force-pushed the randomrotate-cropping branch from db55653 to 87ef6ab Compare March 29, 2026 15:30
@sg3-141-592 sg3-141-592 changed the title Add 'crop' option to RandomRotate Add 'crop' option to RandomRotation Mar 29, 2026
@sg3-141-592 sg3-141-592 marked this pull request as ready for review March 29, 2026 15:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant