2013-07-25

Multiple JPG Edits Degrades Quality

Question: Does editing an JPG image multiple times degrade the image quality, cause shifts in color or loss of sharpness?  Yes.  This is true even if compression is turned off.

Although you can tell your editor to save JPG uncompressed, it still introduces compression and the image quality degrades with each generational edit.  More edits equals more compression.  This article explores loss of quality during multiple editing iterations.

The Experiment:

As an experiment, I took a simple, mostly black and white image, and sent it through ten generations of edits, storing the file uncompressed.  At each step, I checked for changes in color and sharpness.  What I found was each generation had a degradation in quality.

The Test Image:

A simple image showing the letters 'abc', with an anti-aliased red horizontal line (and a pure red control dot, barely visible under the shadow of the 'b').  This image was used because the edges are discernible than a photograph, and this image can be accurately and reliably reproduced.  The image was originally built in PaintShop Pro X5 and was stored in a non-compressed PSPimage format.  For this experiment it was converted to JPG.

Note: This blog only accepts JPG images and has already introduced its own compression.  Because of this, the red is not a pure red in the illustration above.  


Image details:
Original, uncompressed 'abc' as a .pspimage:
Size: 488 x 458px, (195,000 bytes)

An ICC Color profile was not applied
All colors preserved without a loss in quality


Red color palette:
Red = 255
Green = 0
Blue = 0

The test picture has a small, one-pixel, pure-red dot just below the letter 'b''s bowl.  The dot is pure red and is not anit-aliased.  Along with this dot are other anti-aliased pixels, illustrated below, and each was monitored for changes. 

Note the red line marking the base of the font.  This line is anti-aliased and is not, nor expected, to be a pure red.  Magnified 3000%, the areas of interest are shown in this illustration.



Compression

If allowed, all photo-editors aggressively compress images by default -- they will do this with both their native and JPG formats.

For example, in PaintShop Pro (PSP), both the .pspimage and .jpg menus have default compression settings.  For these tests, compression was turned off during the initial File-Save-As.  Adobe Photoshop has similar settings. 

Compression Settings - Click for larger view


When the test file was saved at various compression levels, the file-sizes were:

Test Image File Sizes:
.pspimage - Original 195k  (non-compressed)
.pspimage - default compression lzh       16k  (image not shown in this post)
.jpg - Generation 1 14k
.jpg - Generation 5 17k  (note larger size due to artifacts)
.jpg - Generation 10 17k  (artifacts also shifting in color)

The author recommends turning off compression in all images. In the case of a .pspimage, the default compression is too aggressive.  With JPG's, the space saved is too little to make a difference.

In PSP, change your defaults by opening any image and do a Save-As.  In each format (.pspimage, .jpg, .Tif, etc), click "Options" and choose the compression.  PSP remembers these settings for all subsequent images, until changed.  At the same time, consider disabling ICC profiles, in both the save-as and File, Preferences menus.


First Generation .jpg

Saving from the original, uncompressed .pspimage to .jpg, dropped the file size from (195k) to (14k) - a remarkable drop in size.  Even though PSP was told to not compress, .jpgs, by their very nature have compression.  Here is the first-generation results, at 3000% magnification:


The one-pixel red is no longer red.  Its RGB values should be
R=255,
G=0,
B=0,

but it has already digressed to
R=103,
G=65,
B=64

-- more of a brown than a red.  The first illustration in this article is that first-generation file, with a pure-red control pixel (although, when uploaded to this blog, the blog compressed it).

Notice the horizontal anti-aliased red-line also shifted brown.  The line has numerous pink artifacts one pixel above and two pixels below, which can be seen as a pink shadow.  As more generations are introduced, these artifacts multiply and experience their own color-shifts.

5th Generation .jpg

Opening the first-generation .jpg, I made a tiny, one-dot editing change in a far-corner of the image (not shown in the magnification) then saved and closed the image.  I re-opened and re-edited the remote corner, repeating the save-steps four more times.  The fifth generation edit shows even more dramatic shifts.

The Red pixel shifted to
R = 84 - not even remotely Red
G = 72
B = 74

Other anti-aliasing pixels had similar shifts.  The horizontal red-line now has more artifacts, extending four pixels below and two pixels above.  Their reds have shifted to the thinnest of pink, almost imperceptible.

(Note: The editor disguises some of the compression until the file is actually closed.  This is why the file was closed and re-opened during each pass)


10th Generation .jpg

The 10th generation edit shows less dramatic changes -- after all, most of the red was already compressed out of the image by the fifth generation.


All pixels danced around the previous values, with minor color-shifts downward.  This generation showed more artifacts as the previous shifts continued to drift from their original colors. 


Side-by-Side results

Again, this blogging tool only accepts JPG and by definition, the red-line has already shifted colors.  In reality, this uploaded image is a second-generation .jpg image.  The original image was crystal-clear.  The left-side of the illustration is now a third-generation, while the right-side is a twelfth generation. 

And there are problems with color shifts caused by your monitor, which are not corrected by an ICC profile.  In any case, the editor shows the original (left-side) as a bold, red line, that is pure red, in all of its glory, and the generational images are definitely not red.

What does this mean?

Numerous edits to a .jpg soften quality and mute colors.  This was a stark example and these changes can be difficult to spot at a pixel-by-pixel basis in a normal photograph, but the changes are there.  Photographs are not as compressible as this black, white and red image, but there is compression none-the-less.

There are other caveats with this experiment.  Other photo-editors may behave differently, but I suspect they all do nearly the same thing.  Finally, PSP did not have a zero-percent compression setting for jpg files -- the best it could do was 1%.  I suspect all JPG's must be compressed. 

Consider the first generation save:  Even at a 1% compression, it still dropped the file-size from 195K to 14K -- clearly someone lied.  This appears to be in the design of a JPG file.

Recommendations:

For the best quality photos, follow these recommendations
  • Do not allow the camera to save as .JPG - even at high quality.
  • Save images as RAW.
  • Confirm the photo-editor can read the camera's proprietary RAW format.
    ----------------------------------------------------------------------------
  • Edit photographs in the editor's native format
    (for example, in PaintShop Pro, use .pspimage, Photoshop PSD / PSB).
  • Turn off native compression in the editor.

  • Convert to .JPG as a last-step, if sending in email or posting online; keep originals.
  • If editing in .JPG, turn off file-save-compression!
Of course, this impacts file-sizes.  Non-compressed file-sizes can be painful:

Consider a recent series of photos I took.  5 exposures for one scene.  Each exposure was stored as RAW, then HDR'd into a final image.  Look at these large file sizes -- these have their full fidelity:

Image-1    17MB  (16 megapixels, stored RAW, no compression)
Image-2    17MB - various exposure compensations, 2-5
Image-3    17MB
Image-4    17MB
Image-5    17MB
---------------------
HDR Image - 114 MB -- for one image!

Read about this large HDR image in this related article:
Stanley Forest Burn Photo - imageLiner.blogspot.com


Conclusion:

This experiment was done in pristine conditions, using no compression, and with a relatively simple image.  Now imagine if Paintshop Pro or Photoshop was allowed to compress its .jpg images -- defaulting to a 7 to 20% compression -- this happens each time the file is saved!  Compression (and loss) would be rampant. 

Your comments are welcomed.

Related links:
www.imageLiner.blogspot.com