Search code examples
pythonmathimage-rotationsvd

Rotate image using SVD in Python


I would like to take several rotated images of a rectangular room like this and rotate them such that the long side of the room is parallel to the x-axis like this in Python. A friend recommended using SVD, and from what I understand I need to use the Numpy or SciPy SVD, find the angle difference between the image and the x-axis, and rotate the image by the angle difference. I do not fully understand SVD, so what do I do once I have gotten the SVD?

Any help would be appreciated. Thank you!


Solution

  • SVD is similar to PCA, it will find the "natural" axes in your data (read wikipedia or any other doco for more rigorous explanation of what "natural" means). The U matrix returned by SVD is the rotation matrix you are after (that is between the original x-y axis of your data, and the "natural" axes found by SVD).