Industry guru Dave Taylor offers free tech support on a wide variety of technical and business topics, including HTML, online advertising, Cascading Style Sheets, Web design, management, Unix, Linux, search engine optimization, online dating, Mac OS X, shell script programming and Microsoft Windows.

Why is JPEG considered a "lossy" graphics format?

I'm just starting out in the Web world and was just told by someone else who I respect that I should be careful with the JPEG graphics format because it's "lossy". I have no idea what that means, however. Can you enlighten me?


Dave's Answer:

While I'm a big fan of the JPEG graphics format myself - just about every screenshot on Ask Dave Taylor is in JPEG format - I know exactly what your friend is talking about. A lossy graphics format is one where a small amount of information about the original picture is lost each time the image is saved.

To understand why that happens, it's critical that you know that the Joint Photographic Experts Group "JPEG" format uses a compression algorithm to try and shrink down the resultant image file size. You can see this quite easily by creating a 100x100 pixel solid black image then saving it as a JPEG. It'll be amazingly small considering that it's actually holding information on 10,000 different individual pixels or dots of information (on my Mac, it's only 823 bytes in size).

The specific compression that JPEG uses is quite fascinating, built upon fractals and Mandelbrot sets, but that's another story entirely (which you can start learning about at Bernard Mandelbrot's site)

Anyway, back to lossy JPEG compression!

The problem is that when JPEG compressed images are re-expanded, there's just less information available than there had been before. This doesn't change for a given static JPEG file, but if you keep editing the file, each time you save it, you're compressing it a bit more, that is, losing a bit more information from the original.

Let's have a quick look. First off, here's a nice, detailed original image I'm going to start with:

Tiger Photo, 100% quality, JPEG

This is saved in 100% quality so while it has some loss simply because it's in JPEG format, it's the minimum possible.

Now I'm going to open up and save the image a half-dozen times, using 75% image quality each time so I've got a constantly degrading image. Here's the result:

Tiger Photo, less than 30% quality, JPEG

It still looks surprisingly good, given that the first image is 190Kbytes and the second is only 18Kbytes. A testimonial to the brilliance of the compression algorithm.

But we have lost data. Let's zoom in on the tiger's eye and you'll be able to see what I mean.

In the following image, the eye on the left is from the original Tiger image, and the eye on the right is the same section of the photo, but from the highly compressed file:

Tiger Photo, display of JPEG compression loss

As is clearly obvious, the price we've paid for a much smaller file size is that we've lost quite a bit of the original image detail. In pictures of this nature, it might not seem terrible, but the loss of image data in JPEG format is a significant issue for photographers and others who need to retain original image quality.

Anyway, I hope that clarifies why JPEG is considered a "lossy" format!



Help others find this article at Del.icio.us, Digg, Netscape, Reddit, and Stumble Upon    

Subscribe!

Never miss another useful Q&A article again! Subscribe to AskDaveTaylor with Google Reader.

Comments

I believe JPEG is based on the Discrete Cosine Transform (DCT) followed by quantization -- a sort of "rounding", which is the lossy part -- followed by Huffman (or even arithmetic) coding, and *not* on Fractals or Mandlebrot sets.

See http://www.faqs.org/faqs/compression-faq/part2/

Posted by: Paul Kosinski at August 21, 2005 11:52 PM

Ah, you're absolutely correct, Paul. I don't know where "fractal" got stuck in my head about JPEG compression algorithms. In any case, whatever algorithm is used, the explanation of why JPEG is a "lossy" graphics format is still valid.

Posted by: Dave Taylor at August 22, 2005 5:53 AM

As you yourself pointed out, JPEG stands for Joint Photographic Experts Group. The key word here is "photographic".

You also said "just about every screenshot on Ask Dave Taylor is in JPEG format". Given that JPEG is specifically tuned for photographs, why would you choose it for screenshots? It tends to make unnecessarily bulky and ugly screenshots (and icons, line art, etc.) compared to other formats (specifically GIF and 8-bit PNG). Try it yourself. Compress a screenshot with JPEG and GIF and compare them. 8-bit PNG is even better than GIF, but requires a bit more knowledge of what you are doing -- if you end up with a 24- or 32-bit PNG, it won't be smaller.

JPEG is designed specifically for photographs. It performs well there, but generally not in other areas. There are more appropriate formats for other purposes.

Posted by: Kevin at August 24, 2005 5:02 AM

I agree with your assessment, Kevin, except that from my experience producing a site with a wide readership, I know that not every browser out there has support for PNG format. Then GIFs have problems of their own if you use more than 256 colors or seek color fidelity. Everything has pro's and con's, of course.

Posted by: Dave Taylor at August 24, 2005 5:40 AM

I have a lot to say, but ...
Starbucks coffee cup I have a lot to say, and questions of my own for that matter, but most of all I'd like to say thank you for all your efforts on this Web site by buying you a chai!

I do have a comment, now that you mention it!









Remember personal info?


Please note that I will never send you any unsolicited commercial email. Ever.

While I'm at it, please note that by submitting a question or comment you're agreeing to my terms of service, which are: you relinquish any subsequent rights of ownership to your material by submitting it on this site.









Uniblue: Free Virus Scan

Search
Find just the answers you seek from among our 2000+ free tech support articles by using our Lijit search engine.


Help!





Subscribe to
Ask Dave Taylor!

Add to Google Reader
Add to My Yahoo!
Subscribe in NewsGator Online

RDF   XML

Free Updates!
Sign up and get free weekly updates and special offers on books, seminars, workshops and more.


Recent Entries
Join the List!
Join my author info mailing list, where you'll learn about my upcoming books, speaking gigs, and more!


Book Links
© 2002 - 2009 by Dave Taylor. All Rights Reserved.

Note: This web site is for the purpose of disseminating information for educational purposes, free of charge, for the benefit of all visitors. We take great care to provide quality information. However, we do not guarantee, and accept no legal liability whatsoever arising from or connected to, the accuracy, reliability, currency or completeness of any material contained on this web site or on any linked site.

[whiteboard marker tray]
"Ask Dave Taylor®" is a registered trademark of Intuitive Systems, LLC.