The Tickle Trunk

Guide to JPEG-89 Compression

Send Feedback Home Page > The Tickle Trunk > JPEG 89 Compression

This page contains an applet which demonstrates JPEG-89 compression, including the rarely used Hierarchical variant. The applet will make the most sense if you are already familiar with the technical details of JPEG-89 compression. This is discussed briefly below, but you may find it useful to refer to the Wikipedia article on JPEG for more detail.

The applet requires that your browser support at least the
**Java 2 runtime**.
If the applet above doesn't work properly, this is almost certainly the problem.
You can download the latest Java runtime
from Sun to correct this.

JPEG-89 compression is lossy,
meaning that the reconstructed image has less information than the original* *—
but hopefully the missing information is stuff you wouldn't have noticed anyway.
Two aspects of the human visual system are taken advantage of: the fact that
colour information is less important than brightness, and the fact that we tend
not to notice the details of the parts of an image that are "busy."

To take advantage of the first aspect, the compressor first
separates the image
into three "channels". The first channel (*Y)* contains the brightness information
(it is like a black and white version of the original picture). The other two
channels (*Cb* and *Cr*) contain the colour information. When we get to the actual
compression stage, the compression will be applied more heavily to the colour
channels (they will lose more information). When the image is decompressed, the
reconstructed *Cb* and *Cr* planes will be rather poor imitations of what they
originally looked like— but we won't
notice because the *Y* channel is still a close match, and that's what our
brains really pay attention to.

The second aspect takes a little more work, and sounds a lot like magic in the
space I have to talk about it here. First, what do we mean by "busy"? What
we mean is *high frequency*, which means the image changes a lot over a
short distance. Plaid is a high frequency fabric. Hospital scrubs are not.
So the details of your plaid shirt tend to meld together, and if a stripe is
missing here or there, you won't notice from a distance. In order to find
the high frequency bits in our picture, we first break it up into little squares
(each square is arbitrarily 8x8 pixels). We then use some legerdemain called the
2D Discrete Cosine Transform
(DCT) to transform the information in each square
from the *spatial domain* to the *frequency domain*. The spatial domain is
the one you know and love. In this domain, the information in the upper left
corner of the square is the colour or brightness of the upper-left corner of
that part of the image, while the information in the lower-right corner of the
square is the colour or brightness of the lower-right corner of that part of the
image. But in the frequency domain, the information that ends up in the
upper-left corner of the square is the low frequency stuff, and the information
in the lower-right corner is the high frequency stuff. If you're not used
to such transformations, that will sound like crazy talk. Don't worry, the
applet will make it a bit easier to see what that means. The point is, we
can lose a lot of the information in the lower-right corner of the frequency
domain (and a little of the information in the upper-left). When we decompress
the image, we will reconstruct that information (imperfectly), then apply the
inverse DCT transform to change back from the frequency domain to the spatial
domain, and *hey presto*, you've filtered out the high frequency
information.

With that bit of background in mind, we can see it in action in the applet and get a better understanding. Following the steps in the applet:

- Pick a picture.
- Not only will we compress the colour information more ruthlessly, but we can scale the colour planes down (throwing away 75% of the information they contain), too, and it is still hard to tell when we decompress the image. Try this out after you've finished the rest of these steps.
- Have a look at this table. It has 8 rows and 8 columns, just like the
squares I said we would break the picture up into. The number is the
*inverse*of about how much of the information from that square we will keep. So, 1 means we will keep all of it, while 8 means we will keep 1/8th of it, and so on. Notice that the numbers in the upper-left corner (the low frequency information) are fairly small, while the numbers in the lower-right corner are fairly large (the high frequency information). Also notice the two tabs. The "Luminance" tab shows the numbers that will be used for the brightness channel. The "Chrominance" tab shows the numbers that will be used for the colour channels. The Chrominance numbers are higher because we are compressing the colour information more than the brightness information. There is also a slider here. If you move the slider all the way to the right, all the numbers (in both tables) change to 1 (perfect quality, no loss of information, but no compression). If you move it to the left, they all get very big (worse quality, but better compression since there is less information left). You can experiment by clicking in the cells to set them to whatever you like. Try putting big numbers in the low frequency area and ones everywhere else. - OK, so pick a picture and put the quality slider in the middle. Now look
at the right side of the applet. The top row shows you the original image and
the three channels it is broken into. In the bottom row we have the
decompressed version of those channels and the decompressed image.
*But wait, there's more!* - Click on the drop-down control under the second row of images and pick the
first option (DCTs). This shows you the Discrete Cosine Transform of each
channel. Notice that you can make out the patterns of little 8x8 boxes.
Remember that the upper-left corner of those boxes is the low-frequency part,
the other corner is high-frequency. Brighter pixels mean more information,
*i.e.*more of the image was of that kind of frequency. - Now choose the next drop down item (Quantized DCTs). Whoosh! The lower
corners of each of the 8x8 boxes just went dark. The values in each box were
just divided by the values in the corresponding cells (throwing away any
remainders) of the quantization tables (Step 3), so they now have less
information. The next drop down box shows the reconstructed DCTs,
*i.e.*what we get back when we decompress the image by multiplying by the values in the tables. Compare the original DCT of the colour planes to the reconstructed versions. A*lot*of colour information has been lost, but it is not very noticeable in the final decompressed picture.

Return to Home Page Return to Tickle Trunk Send Feedback

*June 23, 2003 — Updated
January 01, 2011 *