sjrothfuss / torch-rotate-image

Rotate images with torch
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

todo: be explicit about push/pull rotation convention #8

Open alisterburt opened 1 month ago

alisterburt commented 1 month ago

Something we didn't talk about but that is worth being very explicit about is what we mean by 'rotate this image n degrees in this direction'

Right handed rotations in a right handed coordinate system are expected to behave a certain way. We are currently rotating coordinates then sampling at the rotated positions, which has the effect of applying the inverse rotation. c.f. https://en.wikipedia.org/wiki/Active_and_passive_transformation

I think we should explicitly invert this so that the rotation has the same effect on the image we view as applying the rotation matrix on a set of coordinates - what do you think?

sjrothfuss commented 1 month ago

Yes, absolutely. Good catch. I'll be thinking about how to implement this. The first thought I have is to just "invert" the angles (360-n) before rotating coords.

alisterburt commented 1 month ago

Yep! that works for 2D - for 3D you'll want to invert the rotation matrices. torch.linalg.inv() will work and is cheap, I like to use it because it's explicit. Technically more efficient to transpose the rotation matrix rather than inverting it because the transpose of a rotation matrix is its inverse

alisterburt commented 1 month ago

worth adding a note if you implement this to explain what you're doing, it's one of these things that isn't obvious when reading code