Wednesday, October 1, 2003

Understanding how image compression works

.FLYINGHEAD YOUR FIRST DIGITAL CAMERA
.TITLE Understanding how image compression works
.AUTHOR David Gewirtz
.FEATURE
.SUMMARY In this issue, we’re going to look at some important concepts of image compression that you’ll need to know in order to understand how to capture and save images at the best quality.
I have to say that our visit to the world of the digital camera has been pretty amazing. The response we’ve gotten from our readers has been just astounding. In this issue, we’re going to look at some important concepts of image compression that you’ll need to know in order to understand how to capture and save images at the best quality.

But first, I want to comment further about the reader response. Based on your letters, it looks like we’re going to spin out a digital camera publication, most likely to be called "Connected Photographer." We’ve long been thinking about doing a series of publications on the creative arts, but our plans were quite some distance out in the future. Given your interest, we decided to kick things off much more quickly and give Connected Photographer a go.

That said, to make this puppy launch, we’re going to need your help. I’m going to continue to write articles about the cameras and photography, but I definitely need other voices. If you’d like to contribute to the new magazine, please let me know at david@ZATZ.com. We have general writer guidelines at http://www.authorpower.com, but aren’t yet near having a Web site in place for the new magazine. Likewise, if you know of sites who might like to link to us, or companies who might make excellent sponsors (especially if you’re at one of those companies), please let us know as well.

Now, on to the wonderful, wacky world of compression.

Everything we’ve talked about so far has led to the inescapable conclusion that "megapixels" is all about the size of the image, in digital form. The as-yet-undiscussed secret is that an image, when captured on a digital camera, is nothing more than a file, like what you’d find on your computer. Most cameras capture in TIFF (Tagged Image File Format) format, while a few others capture in JPEG (Joint Photographic Experts Group) format.

.H1 The meaning of lossy
In general, you’ll want to make sure your camera can save its image files as TIFF, because JPEG is "lossy." No, not lousy. Lossy. Lossy is actually quite good. Sometimes.

Let me explain. Quite literally, a lossy algorithm, whether we’re talking about pictures or music, is one where the computer (whether on your desktop or inside your camera) is told to purposely lose some bits. I’ll bet some of you are lossy right now, because you’re feeling like your bits are lost. Don’t worry, this is a pretty easy concept once explained.

When we digitize an image or a song, we’re converting a non-digital medium (technically "analog") into a digital medium, a series of bits, or ones and zeros. When an image or sound is digitized at the highest level, the computer (through a series of digitizing peripherals) tries to capture as accurate a representation of the medium as possible. So a photograph, at the highest resolution, attempts to capture as much pixel data as possible. A song, when digitized, attempts to capture every nuance and tone of the music.

In general, at this stage of our technology, the capture can be astoundingly high quality.

So think it through. If you’re capturing at very high resolution and at very high quality, you’re going to be capturing a lot of data. A whole lot of data. But what if you could take that data, say from a song, and save it in a format that takes a lot less storage? We recently captured a four minute song sung by a friend. When stored in the best quality format possible, that song took up 21 megabytes. But when it was converted to MP3 format, that song took up only 969K, less than 5% of the original data size.

Incidentally, this is why the music industry is losing its collective mind. Before MP3 came about, a song took forever to download. But when you can save the song to a format that’s only 5% of the original size, "forever" becomes just a few minutes. And that’s why file sharing services such as Napster and Kazaa took off. The "enabling technology" was the MP3 format, and specifically the compression algorithm in MP3.

So how does it work? What magic happens that makes an MP3 take only 5% of the storage of the original? What magic makes a JPEG take a tenth of the space of a TIFF image file?

One word: compression. Two words: lossy compression.

.BREAK_EMAIL To learn more about compression and your digital camera, click here.

With regular compression, you want to be able to decompress an item later, and have that item be exactly the same as what was originally compressed. Think about your hopes and desires when you ship something to your mom via UPS. When you stick the object in the box, you want it to come back out in perfect condition (or at the very least, the exact same condition it was in when packed into the box originally). Perfect reproduction happens with regular data compression. When you compress a file and then decompress it, the original and the decompressed file are exactly the same.

With me so far?

Now, the thing is, you can only save so much space when you’re using exact (or "lossless," meaning "nothing’s lost") compression.

Lossy compression compresses a file so that when it’s later decompressed, it appears to be the same. But it isn’t. What happens is that some astoundingly brilliant algorithms delete data from the file in such a way that when the file is later reconstructed, you don’t notice the deletions.

In an MP3, this means deleting the sounds the human ear can’t hear. In photographs, this means deleting the variations in color and tone the human eye typically doesn’t notice. By doing this sort of perceptual compression, developers are able to save a huge amount of additional storage.

Now, of course, if you take a picture, you may or may not want to be able to get all the pixels. And that’s why you may or may not want a camera that uses lossy compression as its default format.

.H1 How JPEG deals with compression
As mentioned above, JPEG is a lossy format. But the degree of loss can often be controlled by you. If you’ve got more storage space, you’ll want less loss. At higher degrees of loss, you can start to see some "artifacting," where the compression is no longer making a perfectly clear reproduction upon expanding.

Let’s look at a few examples of this. Note that my images are actually being converted to GIF (Graphics Interchange Format) images for display on the Web, which is lossy in its own way. Normally, you probably wouldn’t convert JPEGs to GIF for Web display, but our journal production system requires it. As a result, you’re going to be seeing a somewhat exaggerated view of the lossitude (not a real word) of these examples.

First, let’s look at Figure A. This is a crop of one of my photographs of Sean, a very nice young model. As you can see, there’s very little artifacting in the image, because it was saved at high quality.

.FIG A There’s very little artifacting when saved at high quality.

Next, let’s look at Figure B. This was saved as a low quality JPEG before being converted to GIF. You can see there’s a whole lot of artifacting in the image.

.FIG B When saved at low JPEG quality, the image gets choppy.

Finally, let’s look at the full image in Figure C. This image, saved as a high quality JPEG takes 73K. When saved at low quality, it takes 25K. By the way, the original of this image, in Photoshop and uncompressed (and at a much larger size than 381×480 pixels, took 29 megabytes.

.FIGPAIR C Here’s the full image. The excessive whiteness on her forehead and arm are the result of the JPEG translation to GIF; another reason why you need to be aware of formats.

.H1 Wrapping it all up
So, what does all this mean? Here’s a quick recap:

.BEGIN_LIST
.BULLET Generally, it’s better to have a starting image that’s been saved in a lossless format. That way, you have all the detail possible to work on the image later.
.END_LIST

.BEGIN_LIST
.BULLET Saving in a lossy compression format like JPEG works, as long as you don’t get too carried away with the compression settings.
.END_LIST

.BEGIN_LIST
.BULLET The more you try to compress, the less you’ll like the results.
.END_LIST

.BEGIN_LIST
.BULLET Try to find camera that has different compression modes as options, so that you can have lossless compression if you want it.
.END_LIST

.BEGIN_LIST
.BULLET That said, cameras that save JPEGs are fine, as long as they don’t overcompress.
.END_LIST

.BEGIN_LIST
.BULLET Lossless and lossy are funny words.
.END_LIST

Take care and I’ll see you next week!

.BIO