This is a quick demonstration of what happens when JPEG is applied repeatedly to an image. It shows how the images change with successive iterations even at the maximum quality settings. The test data is designed to be impossible for default 2x2 colour subsampling to give an accurate rendition of the original image. The target is a single 8x8 block chosen for its simplicity of appearance and difficulty of JPEG encoding. If it was reproduced at normal size you would find it very difficult to distinguish between either of the first generation copies without the aid of a zoom function.
Life size versions are tiny so here is a table with the first generation copies and the original at shown 1x, 2x, 4x magnification.
|Zoom||Original||JPEG 2x2 chroma||JPEG 1x1 chroma|
The first generation JPEG images are both tolerable provided that the resulting image is not subject to excessive enlargement. To emphasise the differences I will use a higher magnification factor of 10x linear size for the tests below.
Repeated compression with PaintShop Pro v5 (IJG codec) at maximum quality. Each successive image has been decoded from the previous generation of data and saved as a maximum quality JPEG with default 2x2 chroma subsampling. There is a huge hit on the first iteration with this line artwork because there is so much fine blue and red detail. Colour contrast is gradually lost with each successive iteration. After a total of 5 iterations the image converges on a solution that is self consistent and stable, though lacking fine detail colour contrast.
Convergence on an attractor like this is less likely in real photographic images at highest quality, but does sometimes occur with them at moderate qualities.
|Original||Generation 1||Generation 2||Generation 3||Generation 4||Generation 5|
Notice how the second and subsequent generations suffer loss of colour contrast through the 2x2 block colour averaging. The extent of the loss surprised me. I think a lot of the generational losses attributed to JPEG are actually down to multiple applications of the chroma subsampling rather than the JPEG algorithm itself.
I should point out that the latest version of Paintshop Pro v8.0 supports a wide range of settings for colour subsampling and not just the basic default 2x2.
Repeated compression with PhotoShop v5.0 (Adobe codec) at maximum quality (10/10) with 1x1 colour sampling. More recent versions have 12 compression levels. You will work hard to spot the difference visually between these and the original target image. The chosen target image is intended to be easy to judge by eye. If you look very carefully you should be able to see a slight checkerboard ripple on the top line of the image. After a total of 6 iterations this test image also converged on a stable attractor. No further changes will occur after this stage .
|Original||Generation 1||Generation 2||Generation 3||Generation 4||Generation 5||Generation 6||Generation 7|
The settings used by PhotoShop for its highest quality JPEG saves do not cause obtrusive artefacts in the first generation, and only cause a very slight loss after the second iteration. The damage is subtle enough that I have included a contrast stretched version below that preserves the original colours but emphasises deviations from them. Armed with the knowledge of where to look and a sufficiently zoomed image you should now be able to see the small artefacts introduced above at generation 2 and higher.
It works surprisingly well on line art considering it was never intended to be used in this way. It is quite a useful means of archiving scanned data in a more compact form than TIFF.
JPEG is much better at compressing normal photographic images accurately than this rather difficult test image. The worst errors occur in the initial step from the original and represent a peak error of 5 in 150 or 3% and an rms error of about 3 in 150 or 2%. After that successive re-compressions at identical settings contribute a cumulative error of less than 1% per iteration.