
I have to give a presentation on a technical topic to a bunch of high schoolers for my thesis class, and I chose the JPEG compression algorithm. Naturally, I knew absolutely nothing about said algorithm when I chose it – and it’s absolutely FASCINATING. I thought I’d put up my slides/explanations here so you too can appreciate the genius that is JPEG.
There are billions of requests for pictures across the internet every second, but the internet can only deliver so much information at a time, making it incredibly important to be able to deliver a picture with as little information as possible. This is the idea of compression – basically, trying to say the same thing with as few words as possible. There are many different techniques to compress digital images, but here I’m going to explain one of the most common ones, the JPEG format.

First, let’s review some of the basics of digital images. As you can see above, zooming in on a normal-looking photograph reveals that it’s made up of lots of little colored squares, known as “pixels.” These pixels store only their individual color value, usually represented as levels of red, green, and blue. In an uncompressed image, the value of each pixel is stored separately in the file, in a binary encoding like the one shown here – but that is not the only option.

The image on the left is uncompressed, the data for each individual picture is stored in the file. The image on the right is a jpeg with maximum compression. You can probably tell some difference already, but let’s look a little closer.

When we zoom in to the face, it starts to look a little blocky. When we zoom in all the way to the nose, it just looks funky. So, what’s going on here, and how does this decrease file size?

There are 3 steps to the JPEG compression method. Color Compression, which involves removing some of the color information, Pattern Recognition, which involves removing pattern information with minimal loss of detail, and Data Simplification, which is a lossless algorithm for compressing binary data. We’ll start off looking at color compression, and see just how color works in JPEG images.

As I mentioned earlier, you can express any digital color in terms of red, green, and blue. If you combine the top 3 images, you’ll get the original picture. If you’re a little skeptical right now, you have a right to be – the primary colors are indeed Red, Blue, and YELLOW, not Green! But that’s just for pigment. When you’re mixing light, like a computer monitor does, red and green make yellow. You can try it yourself with flashlights, it’s pretty neat.
You can also express a colored image in terms of a “Lightness” channel, and 2 gradient “chrominance” channels, which store information about 2 colors each. Here you can see A contains the spectrum of green to red, and B contains the spectrum of blue to yellow. So that’s kinda weird, why does it matter?

If you look at these three images, the lightness image has by far the most detail – it’s just a black and white version of the original. The other two – well, they provide the color to the black and white image, but they’re not so important. The human eye can distinguish contrast and lightness variations much better than it can see color changes. So, let’s get rid of some of that information.

This is what JPEG does to compress color. It actually removes a lot of the color information, so that the smaller A & B color pictures here map to the larger black and white image. This is a psychological/physiological trick employed by the JPEG inventors to great effect.

Here’s a real example of this process. The left is the uncompressed image of the cat’s nose, and the right is the compressed color information from it. Keep in mind the right image is NOT pixels, although it looks like it – the left image is broken into a grid of 8×8 pixel squares, and the image on the right is the average color from those squares.

So, we’ve dealt with the color, now let’s see what we can do with that black and white detail. The square on the left is 64 distinct blocks of gradient patterns that when combined in different ways can make almost any gradient pattern you can imagine.

Here are a few simple examples that you can see being used in the JPEG on the right. These blocks are 8×8 pixels, so instead of storing information for all 64 of them, we simply store 1 piece of information to identify which type of pattern matches the block.

When we combine the black & white pattern information with the color map we produced already, we get a very simplified version of the original picture. Now keep in mind that this is incredibly zoomed in, so while this nose is almost unidentifiable, the full picture of the cat looks just fine.

Let’s see what we’ve got so far. This original image is 650×435 pixels, which is over 280,ooo bits of information. The compressed version is only 81×54 blocks. Multiply by 2 to store the pattern and color information, and you get about 9,000 bits of information. That’s 32 times smaller than the original image! That’s not all we’re going to get, though – there’s still one step left.

This whole concept is about expressing the same thing in multiple ways. This is something that people do a lot with exponents. You can either write out a 1 with twenty zeros following it, or you can just say 10^20. The first takes 21 pieces of information, the second, 4. You can do the same thing with files – the color information for this large block is represented by a ton of zeros, which you can either write out, or just say “it’s 200 zeros.” the final step to the JPEG process goes through the file and combines chunks of information in this way.

Here’s the full process. The uncompressed image gets separated into color information and pattern grids, which are then combined and their data is simplified to give the resulting image. This image, after full compression, is 70 times smaller than the original, meaning it will load 70 times faster in your browser.
Remember that this talk is directed to a high school audience, so I obviously left out all the math and techy details. If you’re interested in that kind of stuff, I pulled most of my info from this excellent article. The jpeg flower and pattern grid were pulled from wikipedia. The kitty picture is one of mine. :)
Tags: compression, jpeg, kitty, Photography, talk










March 14th, 2010 at 2:14 pm
Amazing! I’ve always kind of wondered how jpegs could be compressed since I was 11. Thanks!
[Reply]
April 1st, 2010 at 3:15 pm
That is pretty neat stuff. I *worked* on a wavelet transformation project last semester and learned some interesting things about data compression that I wouldn’t have otherwise.
I was supposed to be finding a way to detect forged handwritten signatures using wavelet analysis, but I didn’t really get any results within the time frame. Professor wasn’t happy but I enjoyed the project.
[Reply]