JPEG: The “E” Stands For “Experts.”
Jul 18th, 2007 by Leo A. Geis
Note: This article is being carried over from the original blog. JPEG encoding is one of the most initimidating, misunderstood, and valuable elements in digital processing. JPEG encoding is completely appropriate for certain archival tasking in even the most demanding digital workflows.
One of the most contentious issues in digital asset management is file compression. The misuse of what are extraordinarily intelligent compression routines has produced a conventional wisdom that .jpg is more of an obstacle to be overcome than a powerful tool offering tremendous benefits.
JPEG stands for “Joint Photographic Experts Group.” The term “Experts” is not hyperbole.
The classic .jpg compression with which most practitioners are familiar is in fact a “lossy” compression algorithm, and the derogatory effects of the compression increase as the compression is more aggressively applied. There is rarely an obligation to use any particular compression level, and in fact each image will react differently to various compression levels.
In .jpg compression, the raster image is first converted to a special color space (“gamut”) friendly to the algorithm, and then divided into 64-pixel squares (8 pixels by 8 pixels) on a per-channel basis. If the division isn’t perfect (there may be some pixels left over), the algorithm compensates. Next, a formula is written for each 8×8 block. That formula takes into account image characteristics, issues of human visual acuity and color management. Finally, everything is packaged up back into your specified color space, tagged, and saved. The names of various process elements are intimidating: Discreet Cosine Transform, Quantization, Chroma Subsampling, et. al.
Derogatory effects are additive if you recompress an image with a different compression setting than its original. In other words, opening an image in PS at a compression level of 4/12, then saving it again (without manipulation) at 4/12 will not further degrade the image. Saving it at 2/12 or 6/12, or after further manipulation (excluding metadata or immaterial changes) will.
At various compression levels, the 8×8 encoding blocks of .jpg become obvious and are generally considered objectionable. .jpg corruption usually manifests as apparent waves, particularly along high contrast edges-those waves are referred to as “artifacts.”
A demonstration of compression derogation:
- Open an image you consider sharp. Duplicate it (left-click on the image’s Title Bar and select “Duplicate”), and resize the duplicate down to 1/4 it’s original dimensions.
- Duplicate your duplicate several times so that you have perhaps 6 iterations.
- “Save As” each iteration at a different .jpg compression level, e.g. 2, 4, 6, 8, 10, and 12/12.
- Reopen all the images and zoom in (for example, Ctl-+ to 200% or 400% on each). Take note of at which compression level the 8×8 blocks appear to be obvious, then obnoxious.
- Using your Info Palette (Window>Info, or just press F8) you will be able to locate individual pixels and check their constituent colorsĀ (zoom in to 1600%, and reference which pixel you are hovering over by checking the X and Y coordinates of the pixel in your Info Palette). Compare individual pixel color constituencies from image to image, and note how much corruption seems to occur in areas of smooth tonal change (e.g. the sky) vice around sharp, high contrast edges (e.g. the center aisle in the US Senate).
- Quantify the amount of corruption across a statistically significant sample of pixels at compression level 10/12. If you have no interest in statistics or don’t have SPSS at home (after all…who would?), try this site.
- Sit back in amazement as your realize that uncorrected (.tif’s from “neutral” Canon RAW) aerial images, even in the aRGB color space, endure tonal corruption of as little as 1/3 of 1% (~.003 of the total range) at .jpg 10/12, even in the most hostile areas (around high contrast edges). Particularly if you have a calibrated monitor/s, test yourself to see if you can see the difference. Consider this inaccuracy weighed against other corruptive influences such as color temperature, optical vignetting, focal and motion blur, Chromatic Aberrations, et. al.
- Resolve never to make disparaging remarks about properly employed .jpg again.
Here’s another instructive experiment:
- Open an image representative of your work (presuming you are a skilled photographer with at least an 8MP DSLR).
- Duplicate it 3 times.
- Apply Gaussian Blur to Copy 1 (at Radius 1) and Copy 2 (Radius 8).
- “Save As” each iteration at the same compression. Try 10/12, but be sure to label each file discreetly.
- Look at the file sizes on your hard drive. Isn’t that simply amazing? Consider the implications for low-bandwidth raster transfer on low-resolution images (such as in Flash Lite applications).
To be sure, classic .jpg has it’s limitations: No Layers or Alpha Channels, 8-bit only, and no truly lossless compression. However, JPEG 2000 (“.jp2,” a much different animal than .jpg) does have a lossless option (it is very processor intensive), allows the practitioner to specify a final file size, and is compatible with Alpha Channels.
A bit on strategy: Although you can’t save Layers in .jpg or .jp2, there’s nothing preventing you from saving those Layers as separate files…but no, it doesn’t work on Adjustment Layers. You can save Adjustment Layers stacked with a Fill Layer, even if the Fill Layer isn’t rasterized…this makes for some very small auxiliary files containing all the Adjustment Layers of an image. Practitioners with advanced automation (.atn, Photoshop Actions) and scripting (.js, Photoshop Scripts) capabilities will recognize this potential…
L




