Is rotating an image by a non-90° angle inherently lossy?
Asked 8/23/2013
4 views
2 answers
0
When you rotate a raster image by an angle that is not a multiple of 90°, the pixels no longer line up with the original grid, so the software has to interpolate new pixel values. Is that process inherently lossy for bitmap images, even if you rotate the image back afterward? Does the answer depend on the interpolation method, such as nearest-neighbor versus bicubic, and can increasing resolution make the process effectively reversible?
Originally by Photography Stack Exchange contributor. Source · Licensed CC BY-SA 4.0
Photography Stack Exchange contributor
12y ago
2 Answers
9
Image rotation is a lossy operation, but rotating an image once then rotating it back likely loses very little detail, especially compared to typical JPEG compression.
Image rotation works like this mathematically:
A grey level image consists of luminance values L_(x,y) at integer pixel positions x, y. First a real-argument function f(x,y) is constructed that reproduces the values L_(x,y) at the same x,y positions, but will also give values at non-integer x,y. Hence it's interpolating between integer x,y positions (this is where interpolation methods come in---there are several possible choices for f(x,y)).
Then construct a rotated version g(x,y) = f( x cos(a) - y sin(a), x sin(a) + y cos(a) ) by angle a. This operation is mathematically lossless, not counting the numerical roundoff errors when performing the calculation on a finite precision computer.
Finally g(x,y) values are calculated at integer x,y positions again to create an image.
At this point you can ask: why is this lossy? Can't we just reverse all these calculations to reconstruct the original unrotated L_(x,y), if we know what interpolation method was used to construct f?
Theoretically that is possible, but this is not what happens when you do a rotation of the same angle in the opposite direction. Instead of reversing the original rotation operations precisely, an opposite sign rotation is performed using the same sequence of operations that the initial rotation used. The back-rotated image will not be precisely the same as the original.
Furthermore, if the values of g(x,y) were rounded to a low precision (8-bit, 0..255), the information loss is even greater.
Lots of accumulated rotations will effectively blur the image. Here's an example of rotating a 500 by 500 pixel Lena image 30 times by 12 degrees, amounting to a full 360 degree rotation:

There's another reason why blur-type operations will be lossy. One might naively think that mathematically reversing a blur should give us back the original unblurred image. This is theoretically true for as long as we're working with infinite precision. The procedure is called deconvolution and it is being used in practice to sharpen images that are blurry due to motion blur or optical reasons.
But there is one catch: blurring is insensitive to small changes in the source image. If you blur two similar images, you get even more similar results. De-blurring is very sensitive to small changes: if you de-blur two only slightly different images, you get two very different results. We're usually not working high precision (8 bit is quite low precision actually), and the roundoff errors will get magnified when attempting to reverse a blur.
This is the reason why blurring is "irreversible" and why it is losing detail.
Originally by user10147. Source · Licensed CC BY-SA 4.0
user10147
12y ago
0
Generated from our catalog & community — verify before relying on it.
For raster images, yes: rotating by a non-90° angle is effectively lossy in practice. The geometric rotation itself is not the problem mathematically; the loss comes from resampling the image onto a fixed pixel grid.
After rotation, most source pixels no longer fall exactly on output pixel centers, so software must interpolate. With nearest-neighbor, values are reassigned to the closest pixel, which discards positional information. With bicubic or similar methods, values are spread among nearby pixels, which also cannot be perfectly undone once sampled back onto the grid.
Rotating back usually loses only a small amount of detail, but it will not generally reproduce the original image exactly. The interpolation method changes the character of the error, not the fact that resampling introduces it.
In theory, if you increased resolution enough, the error could be made very small, but that would require adding many more samples. Practically, if exact reversibility matters, it is better to keep the original image and store the rotation as metadata or as an edit instruction rather than repeatedly rotating pixel data.
Recommended products
UniqueBot
AI12y ago
Your Answer
Related Questions
How can I detect whether a JPEG has been upscaled from a smaller original?
Can a TIFF be rotated 90° without re-encoding or increasing file size?
How do I rotate a photo by an exact angle in Lightroom, not just 90° increments?
Can Lightroom rotate or straighten a photo by a small arbitrary angle?
How can I photograph vineyard rows in a panorama so the nearest row looks straight instead of bending at the edges?