JPEG compression

JPEG stands for Joint Photographic Experts Group, which is a standardization committee. It also stands for the compression algorithm that was invented by this committee.

The JPEG algorithm has been conceived to reduce the file size of natural, photographic-like true-color images as much as possible without affecting the quality of the image as experienced by the human sensory engine.

  • JPEG compression is lossy: when you decompress a JPEG compressed image and compare the result to the original image that was compressed, there will be differences and a loss of detail and sharpness in the decompressed image. Other compression algorithms like LZW are lossless: the decompressed image is identical to the original image.
  • We perceive small changes in brightness more readily than we do small changes in color. The human visual system is also not that good at dealing with high frequency data – if image details change very quickly in part of an image, our brain cannot really process all those changes.  These two aspects of our perception are used in JPEG compression to reduce the file size of an image.
  • JPEG compression does not use a single fixed way of compressing data. The algorithm can compress image data heavily with a significant loss of detail, or it can limit the loss of detail by lowering the compression ratio.  In applications like Adobe Photoshop, a slider allows you to select the compression ratio.
  • There are two JPEG compression algorithms: the oldest one is simply referred to as ‘JPEG’ within this page. A separate page discusses the newer JPEG 2000 algorithm.
  • You have to make a distinction between the JPEG compression algorithm and the corresponding JFIF file format, which many people refer to as JPEG files and which is discussed in the file format section.

How JPEG works

The JPEG algorithms perform compression in phases:

  • Our visual system is less sensitive to changes in color (chrominance) than changes in brightness (luminance). The JPEG algorithm is based on this difference in perception. It does not analyze RGB or CMYK color values but instead uses a luminance/chrominance based color space called YCbCr. In this color space, the Y channel carries luminance data while the Cb and Cr channels contain color information. This allows for separate compression of these two factors. Since luminance is more important than chrominance for our visual system, the algorithm retains more of the luminance in the compressed file and downsamples the color information, typically by a factor of 2 in both the horizontal and vertical direction.

Please note that the above step is not mandatory in the JPEG specs: the full specification also allows the use of the RGB color model but in practice most applications do perform that conversion to the YCbCr color space.

The YCbCr color space is only used internally. You do not notice its use as a user. After decompressing a file that was JPEG compressed, you once again have an image that has the same color space as the source image.

  • The JPEG algorithms then cut up the image in separate blocks of 8×8 pixels. The compression algorithm is calculated for each separate block, which explains why these blocks or groups of blocks become visible when too much compression is applied. Compression is also applied separately to the Y, Cb and Cr channels.
  • For each 8×8 block, a Discrete Cosine Transform (DCT) transformation is applied. In this complex process, the intensity levels of all 64 pixels are replaced by values that describe how those values could be calculated using a mix of mathematical functions. This operation does not compress the file, it simply replaces 8×8 pixel values by an 8×8 matrix of DCT coefficients.
  • Once this is done, the actual compression can start. First the compression software looks at the JPEG image quality the user requested (e.g. Photoshop settings like ‘low quality’ or ‘medium quality’) and selects an appropriate quantization table. This is a matrix of 8×8 numbers. Then the software divides each of the 8×8 DCT coefficients by its corresponding constant in the 8×8 quantization table and rounds off to the nearest integer. The quantization table favors small or gradual changes over high frequency changes. As was stated early in this topic, our visual system cannot easily cope with rapid repetivite changes in image data, so the algorithm favors gradual tonal changes. The result of this quantizing step is that you go from a matrix that contains 64 numbers that are potentially all different to a new table that contains much lower numbers, which are more likely to either have the same value or, for high frequency patterns, be zeros. The new 8*8 matrix still roughly describes how to reproduce the original 8*8 tonal values, but the rounding-off has caused a loss in image quality.
  • A table that contains many numbers that are either identical or zero is easy to compress. The last step in the process is to compress these coefficients using either a Huffman or arithmetic encoding scheme. Usually Huffman encoding is used. This lossless compression leads to yet another reduction in file size.

Advantages

By combining several compression algorithms, JPEG achieves remarkable compression ratios. Even for prepress use, you can easily compress a file to one-fifth of its original size. For web publishing or e-mail exchange, even better ratios up to 20-to-1 can be achieved.

JPEG decompression is supported in PostScript level 2 and 3 RIPs. This means that smaller files can be sent across the network to the RIP which frees the sending station faster, minimizes overhead on the print server and speeds up the RIP.

Disadvantages

The downside of JPEG compression is that the algorithm is only designed for continuous tone images (remember that the P in JPEG stands for Photographic). JPEG does not lend itself for images with sharp changes in tone. There are some typical types of images where JPEG should be avoided:

  • images that have had a mask and shadow effect added to them in applications like Photoshop.
  • screen dumps or diagrams.
  • blends created in Photoshop.
  • images containing 256 (or less) colors.
  • images generated by CAD-CAM software or 3D applications like Maya or Bryce.
  • images that lack one or more of the process colors. Sometimes images are created that use for instance only the magenta and black plate. If such an image is compressed using JPEG compression, you may see artifacts show up on the cyan and yellow plate.

Because of its lossy nature, JPEG should only be used during the production stage of prepress (making PostScript or PDF, imposing, proofing, outputting). During the create process when images are still edited, cropped and colour corrected, each new SAVE-command leads to extra loss of image quality when JPEG is used.

Where is JPEG compression used

JPEG compression can be used in a variety of file formats that are commonly used in graphic arts:

  • EPS files
  • EPS DCS files
  • JFIF files
  • PDF files

Other sources of information

Computerphile published two videos about JPEG compression: The first one covers the overall algorithm and the way it used color information. The second video goes into more detail on DCT.

4 thoughts on “JPEG compression

  1. > Humans are more sensitive to changes in hue
    > (chrominance) than changes in brightness (luminance).

    Isn’t that backwards? Note that later the same paragraph says:

    > Since luminance is more important than chrominance for
    > our visual system, …

  2. So we charge our customers top dollar for the highest resolution scans possible, Then, right before we ship the product, we let a computer decide on how much of that product really gets shipped, based on the fact the customer will never notice.
    hmmmm.
    OK

Leave a Reply

Your email address will not be published. Required fields are marked *