I have used imrotate
function to rotate an image without using the 'crop'
argument and now after some processing I would like to imrotate back to have the original orientation and size. Is there a way to do that, maybe with other functions other than imrotate?
Asked
Active
Viewed 924 times
1

Daniel Heilper
- 1,182
- 2
- 17
- 34

umbe1987
- 2,894
- 6
- 35
- 63
-
Use negative of the angle used for `imrotate`? – Divakar May 26 '14 at 12:55
-
not working, that's why I'm asking. – umbe1987 May 26 '14 at 13:01
-
What are you getting when using another call to `imrotate` with the negative angle? – Divakar May 26 '14 at 13:03
-
do you rotate by angles that are multiples of 90' ? – Daniel Heilper May 26 '14 at 13:23
-
the image is now bigger (as I would expect after using imrotate without 'crop' argument). I'd like to have the same (but very same) size as the original. The problem is that imrotate alters the size of the image after rotating to be large enough to contain the entire rotated image. – umbe1987 May 26 '14 at 13:24
-
no, it's actually something like 332deg. – umbe1987 May 26 '14 at 13:25
-
@umbe1987 It must have added black borders on all four sides of the final image that you need to crop out based on the sizes of the original image. – Divakar May 26 '14 at 13:39
-
You want to rotate the image back and in such a way that it will be identical to the original image? – Daniel Heilper May 26 '14 at 13:39
-
yes, except some modifications I've made to some pixel value. Anyway, I am trying to find out if the image center is still the same to possibly crop myself the image back to the original size. – umbe1987 May 26 '14 at 13:51
-
What's wrong with simply performing the reverse rotation on the modified pixels **only** and deciding how to antialias the resulting points on the original image? – beaker May 26 '14 at 15:49
1 Answers
1
If the rotation angle is not a multiple of 90' - 0', 90', 180', ... , There is no way to rotate back and get the exact original image. The reason is that the rotation of an image is a non-linear transformation - see in mathworks-ref-imrotate. The rotation is performed using interpolation, where the default is "nearest". In your case theta=332' the transformation is non preserving.
So the answer is no.
Note: For theta = K*90' there is a linear transformation - 2X2 rotation matrix, and also you can use a combination of flip and transpose: easiest-way-to-transpose-an-image-rotate-by-90-degrees-using-opencv

Community
- 1
- 1

Daniel Heilper
- 1,182
- 2
- 17
- 34
-
Right. The best approximation to obtain a similar (not equal) image as respect the original is then to crop the double-rotated image (with the original orientation) according to the difference between the number of columns and rows between the original image and the processed one and knowing the rotation has been made on the center of the image. Thanks for the clarification. – umbe1987 May 26 '14 at 15:44