Lossless JPEG rotation only lossless at 360 degrees?
Posted: Tue Dec 01, 2009 5:47 am
Potential Problem:
While trying out the lossless JPEG rotation feature in XnView 1.97, I found something strange:
The rotation appears to be "lossy" for rotations of 90, 180, and 270 (e.g. 90 + 90 + 90) degrees. However, if I continue rotating until the image has the original orientation (e.g. 360 degrees), the result is identical to the original image.
This suggests that the pixel data is being rotated losslessly, but something else in the file (e.g. quantization matrix) isn't being correctly changed to accommodate the rotation.
Steps to Reproduce:
1) Download http://commons.wikimedia.org/wiki/File:Notre.JPEG or use another image whose dimensions are divisible by 16.
2) Make a copy of the file for comparison purposes.
3) In XnView, check all boxes under Options -> Browser -> Misc.
4) From the XnView browser, right-click the file and choose JPEG Lossless transformations -> Rotate 90 degrees right.
5) Open the rotated file in an image editor, e.g. GIMP or Paint.NET.
6) In the image editor, rotate the modified image 90 degrees to the left. It should have its original orientation.
7) Open the copy of the original file in the image editor.
8) Paste the modified image into a new layer on top of the original image.
9) Set the top (modified) layer to use the "Difference" blending mode. The image should turn black.
10) Merge down or flatten the layers to a single black layer.
11) Check for pixels that aren't completely black, indicating a lossy change. In GIMP, you can use the histogram to look for any pixels with a value greater than 0. In Paint.NET, you can adjust the levels (or use auto-level) to look for non-zero pixels.
Related Information:
I searched the forums and noticed that some people have complained of lossy rotations, while others say it is lossless. Perhaps the discrepancy is caused by some people doing 360 degrees of rotation before checking if it is lossless.
To compare an image that is rotated less than 360 degrees with the original image, you have to rotate the result back to the original orientation using a third party program, such as Photoshop or GIMP. To ensure the error is not caused by a third party program, I used multiple programs to verify the result and tested their rotation ability with lossless PNGs.
While trying out the lossless JPEG rotation feature in XnView 1.97, I found something strange:
The rotation appears to be "lossy" for rotations of 90, 180, and 270 (e.g. 90 + 90 + 90) degrees. However, if I continue rotating until the image has the original orientation (e.g. 360 degrees), the result is identical to the original image.
This suggests that the pixel data is being rotated losslessly, but something else in the file (e.g. quantization matrix) isn't being correctly changed to accommodate the rotation.
Steps to Reproduce:
1) Download http://commons.wikimedia.org/wiki/File:Notre.JPEG or use another image whose dimensions are divisible by 16.
2) Make a copy of the file for comparison purposes.
3) In XnView, check all boxes under Options -> Browser -> Misc.
4) From the XnView browser, right-click the file and choose JPEG Lossless transformations -> Rotate 90 degrees right.
5) Open the rotated file in an image editor, e.g. GIMP or Paint.NET.
6) In the image editor, rotate the modified image 90 degrees to the left. It should have its original orientation.
7) Open the copy of the original file in the image editor.
8) Paste the modified image into a new layer on top of the original image.
9) Set the top (modified) layer to use the "Difference" blending mode. The image should turn black.
10) Merge down or flatten the layers to a single black layer.
11) Check for pixels that aren't completely black, indicating a lossy change. In GIMP, you can use the histogram to look for any pixels with a value greater than 0. In Paint.NET, you can adjust the levels (or use auto-level) to look for non-zero pixels.
Related Information:
I searched the forums and noticed that some people have complained of lossy rotations, while others say it is lossless. Perhaps the discrepancy is caused by some people doing 360 degrees of rotation before checking if it is lossless.
To compare an image that is rotated less than 360 degrees with the original image, you have to rotate the result back to the original orientation using a third party program, such as Photoshop or GIMP. To ensure the error is not caused by a third party program, I used multiple programs to verify the result and tested their rotation ability with lossless PNGs.