Saturday, June 03, 2006

JPEG Myths

Today was a rainy day, so Diddlbiker decided to try something out. What I wanted to do was show how image quality deteriorates through subsequent saves as a JPEG file. After all, JPEG is a lossy format, so every time you save, you lose some image quality, right?
Wrong. It seems that the truth is slightly more complicated. Save a picture with exactly the same image quality over and over again, and the image data will be saved in exactly the same way. Here is an illustration:




















This is the original picture.
This is the picture saved at a 25% quality level. Yes, it's pretty bad.
This is the previous picture opened, and saved again at a 25% quality level. You'd expect an even worse picture, but it looks exactly the same!
The process is repeated two more times (four times in total), but no difference with the first picture...

Amazingly, image quality doesn't degrade over consecutive saves. There is the loss of image quality due to the JPEG quality used, but that's about it. I'm figuring that once the JPEG compression has taken place, the end result will, when compressed again, yield the same file. Some caveats however:
  • This only works if the picture stays the same (except for the parts that are changed, of course). Resize the picture, crop it, add border around, mirror, etc, and you'll get another round of quality degradation. Any part that is changed will suffer as well of course.
  • There is of course the initial quality loss - and there's not a lot of difference in file size between 95% quality and 75% quality (more about that in another blog)
  • JPEG supports rotation (at 90 degrees) as well. If you are using a good image editor, all that wil happen when you rotate the picture is that a rotation flag will be changed - the picture itself will still stay unchanged.
Lesson learned: never believe 'general knowledge' if you can check the results for yourself - happy experimenting!

No comments: