62

Can I rotate lossily compressed photos that I view in Windows Photo Viewer without worrying about losing even more information to compression?

  • Why don't you try it? Copy an image. Rotate several times and see if it comes back identical. I noticed for example with Picasa the files loses about 20% size after the first 90-degree turn. On the other hand you can simply get a software with that explicit feature. ( PMView Pro is my favorite since its very efficient and super fast, its cheap too: http://www.pmview.com ) – Itai May 24 '11 at 13:18
  • @Itai: I've tried, and the size increases after turning and turning back. That does not mean that information is lost, though. –  May 24 '11 at 13:22
  • By "Windows Photo Viewer" do you mean the default viewer that comes with Windows 7? – Matt Grum May 24 '11 at 14:20
  • @Matt Grum: Yes. –  May 24 '11 at 14:42
  • @Matt Grum: It came installed under Program Files\Windows Photo Viewer for my Acer Aspire with Windows 7. –  May 24 '11 at 15:02
  • Bigger! That is strange but I am not entirely surprised given the vendor of that software ;) At least there is a chance it is lossless. What you need to confirm is an image difference tool. Those are simply software that show you the difference between two images and compare the original and rotated image. – Itai May 24 '11 at 15:55
  • 1
    Note that--as far as I know--a 90 degree rotation (and 180, 270) is lossless in and of itself because it is a swap of x and y coordinates (other angles require interpolation). So any lossyness attributed to the transform is from the recompression. You can avoid this recomputation by saving the transformed image in a lossless format, but that is clearly not part of your question, so I won't suggest it – horatio May 24 '11 at 18:32
  • 6
    @horatio, the multiples of 90 degrees are a special case for JPG compression, where it is technically possible to rotate the image without a compression cycle by "simply" rearranging the compressed data. It does involve removing and applying a layer of lossless compression, so the file size might change, but no lossy operations are required. – RBerteig May 24 '11 at 18:54
  • 1
    I think I understand you, but my point is that jpeg is a disk storage format and does not have any bearing on the quality of the transforms themselves. That is to say, though one often speaks of working with jpegs etc, while the file is displayed on screen and manipulated, it is not a jpeg. – horatio May 24 '11 at 19:59
  • 1
    Man I have ALWAYS wanted to know the answer to this question. IMO they SHOULD be. But most likely due to the JPEG standard... I don't think it is technically possible to make this operation lossless. – Trevor Boyd Smith May 24 '11 at 20:46
  • 2
    Google Picasa image viewer IS lossless. but it cheats. it doesn't rotate the image. it just marks down in meta data "display this image rotated". – Trevor Boyd Smith May 24 '11 at 20:46
  • file size changing is suspicious. i don't have win7. someone should do a image diff: outcome should be completely black/white (make sure to check that there are no small values). – Trevor Boyd Smith May 24 '11 at 20:53
  • 1
    Did Picasa change that recently? When I worked at Google 1 1/2 year ago I actually asked the lead architect about that and the answer was that they first marked the image as rotated but then did the rotation (which reduced the image size) when the unsaved edits were applied. – Itai May 24 '11 at 21:12
  • 1
    For me, if you delete the .meta file (which is created next to the image) the photo gets display by picasa viewer as un-rotated. so ya... it isn't rotating the image but just sees in meta data "display as rotated". – Trevor Boyd Smith May 27 '11 at 16:14
  • I'm also interested to know if rotaing an iPhone photo results in a recompressed JPG??? The anwers above don't really help ... why the heck is the onboard Photo Viewer of Windows 7 still not able to handle the rotation information? Any other program or platform is presentating the photo correctly based on the header information. –  May 21 '12 at 14:52
  • (i) Picasa stores image transformation information in .picasa.ini files. Delete the file and restart picasa, you will notice that images that were rotated using picasa are no longer rotated.(ii) the windows 10 photo viewer app seems to alter the meta data -- the file size remains identical. – Salman A Apr 18 '16 at 15:09

1 Answers1

67

If the dimensions of the image are multiples of 8 (or 16 if chroma subsampling is used) then the rotations are lossless. Otherwise it is not possible to rotate the image without recomputing the blocks i.e. recompressing the image, which is lossy.

The reason for this is that jpeg images are broken up into a series of 8x8 or 16x16 blocks which are compressed individually. Incomplete blocks are only allowed on the right edge and bottom edge. Thus is your image is not an exact multiple of 8/16 it will contain incomplete blocks, which will end up on the wrong edge after rotation.

I verified the above assertion using the version of Windows Photo Viewer that ships with Windows 7. I used two images of colour noise. One image was 256x256 i.e. both sizes multiples of 8. The other image was the same but cropped to 253x253 i.e. neither size was a multiple of 8. Here are the images:

256x256

253x253

I then performed four anti-clockwise rotations, closing photo viewer after each rotation to ensure the image was saved in it's rotated state.

256x256

253x253

There's no need to perform a subtraction to see the difference with the 253 pixel image, it's noticeably darker and muddier!

A diff on the other image looks like this:

i.e. the images are identical, the rotations were lossless.

Matt Grum
  • 118,892
  • 5
  • 274
  • 436
  • 1
    I know that in the past when I've done rotations it has warned me that the rotation would be lossy, which implies that in cases where the warning wasn't displayed the transformation was lossless, but I didn't check. Nor do I remember what version of WPV I was using, not precluding the possibility that MS changed the codebase, so no I can't be sure. – Matt Grum May 24 '11 at 13:55
  • 1
    @Tim an image of pure noise is by definition the worst case for jpeg (or any compression algorithm), which is why I chose it! Results on real images would look better. – Matt Grum May 26 '11 at 15:12
  • 1
    @MattGrum, very cool demo. I hope all digital camera makers have their image sizes in integer multiples of 8! – Trevor Boyd Smith May 27 '11 at 16:36
  • 1
    @MattGrum I used to work on the WPV team. AFAIK, (and I'm pretty sure) your answer is correct. Also, +1 for a very thorough method of proving your hypothesis : ) – Tristan Aug 06 '13 at 16:53
  • @TrevorBoydSmith every camera I've seen has image dimensions that are a multiple of 8 or 16. Rotation isn't necessarily the reason, it may just allow some optimization of the JPEG pipeline. – Mark Ransom Oct 10 '19 at 22:47