vision icon indicating copy to clipboard operation
vision copied to clipboard

Add support for recentering for RandomAffine and RandomPerspective transformations

Open Chiptun3r opened this issue 1 year ago • 1 comments

🐛 Describe the bug

It is sometimes the case that the dataset you’re working on contains objects always in the same position and you want to keep that property during the augmentation. I suggest to add an argument to the RandomAffine and RandomPerspective transforms that, when enable, locate the old center of the image in the transformed one and translate it back to the center. Also, it maybe be useful to extend this feature to any arbitrary point, so that, if one point is specified in the original image, it will get translated back to its original place after the transformation

Versions

torchivision 0.18.1

Chiptun3r avatar Jun 26 '24 07:06 Chiptun3r

Thanks for the feature request @Chiptun3r .

Correct me if I'm wrong: a call to RandomAffine where we then re-center the image seems to be equivalent to RandomRotation + RandomZoomOut?

That being said, I'm not sure I completely understand the original need, in particular:

It is sometimes the case that the dataset you’re working on contains objects always in the same position and you want to keep that property during the augmentation

Can you provide more details about this? IIUC, the only point that you would like to be kept in the same position is the center of the image (all other points will end up in different places)?

NicolasHug avatar Jul 25 '24 14:07 NicolasHug