Jpeg FAQ ( Straight from the horses mouth )

Rob Harper Rob.Harper at CONVEX.CSC.FI
Sun Dec 15 13:59:17 EST 1991

>Xref: funic news.answers:200
>From: tgl+ at (Tom Lane)
>Subject: JPEG image compression: Frequently Asked Questions
>Summary: trying to clear up some of the confusion
>Keywords: JPEG, image compression, FAQ
>Message-ID: <faq_692812338 at>
>Date: 15 Dec 91 15:52:26 GMT
>Expires: Sat, 11 Jan 92 15:52:18 GMT
>Reply-To: jpeg-info at
>Organization: School of Computer Science, Carnegie Mellon
>Lines: 437
>Approved: news-answers-request at MIT.Edu
>Supersedes: <faq_691648194 at>
>Originator: tgl at G.GP.CS.CMU.EDU

Archive-name: jpeg-faq
Last-modified: 15 Dec 1991

This FAQ article discusses JPEG image compression.  Suggestions for
additions and clarifications are welcome.

This article includes the following sections:

1)  What is JPEG?
2)  Why use JPEG?
3)  How well does it work?
4)  What are good "quality" settings for JPEG?
5)  When should I use JPEG, and when should I stick with GIF?
6)  Where can I get JPEG software?
7)  What's all this hoopla about color quantization?
8)  How does JPEG work?
9)  What about lossless JPEG?
10)  Why all the argument about file formats?
11)  And what about arithmetic coding?

Sections 7 and up can be ignored unless you are interested in details.

1)  What is JPEG?

JPEG (pronounced "jay-peg") is a standardized image compression mechanism.
JPEG stands for Joint Photographic Experts Group, the original name of the
committee that wrote the standard.  JPEG is designed for compressing either
full-color or gray-scale digital images of "natural" (real-world) scenes.
JPEG does not handle black-and-white (1-bit-per-pixel) images, nor does it
handle motion picture compression.  (Standards for compressing those types
of images are being worked on by other committees, named JBIG and MPEG

JPEG is "lossy", meaning that the image you get out of decompression isn't
quite identical to what you originally put in.  The algorithm achieves much
of its compression by exploiting known limitations of the human eye, notably
the fact that small color details aren't perceived as well as small details
of light-and-dark.  Thus, JPEG is intended for compressing images that will
be looked at by humans.  If you plan to machine-analyze your images, the
small errors introduced by JPEG may be a problem for you, even if they are
invisible to the eye.

A useful property of JPEG is that the degree of lossiness can be varied by
adjusting compression parameters.  This means that the image maker can trade
off file size against output image quality.  You can make *extremely* small
files if you don't mind poor quality; this is useful for indexing image
archives, making thumbnail views or icons, etc. etc.  Conversely, if you
aren't happy with the output quality at the default compression setting, you
can jack up the quality until you are satisfied, and accept lesser compression.

2)  Why use JPEG?

There are two good reasons: to make your image files smaller, and to store
24-bit-per-pixel color data instead of 8-bit-per-pixel data.

Making image files smaller is a big win for transmitting files across
networks and for archiving libraries of images.  Being able to compress a
2 Mbyte full-color file down to 100 Kbytes or so makes a big difference in
disk space and transmission time!  (If you are comparing GIF and JPEG, the
size ratio is more like four to one.  More details below.)

Unless your viewing software supports JPEG directly, you'll have to convert
JPEG to some other format for viewing or manipulating images.  (Right now,
not many viewers include JPEG support, but this will change rapidly.)  Thus,
using JPEG is essentially a time/space tradeoff: you give up some time in
order to store or transmit an image more cheaply.

It's worth noting that when network or phone transmission is involved, the
time savings from transferring a shorter file can be much greater than the
extra time to decompress the file.  I'll let you do the arithmetic yourself.

The other reason that JPEG will gradually replace GIF is that it stores full
color information: 24 bits/pixel (16 million colors) instead of 8 or less
(256 or fewer colors).  If you have only 8-bit display hardware then this
may not seem like much of an advantage to you.  Within a couple of years,
though, GIF will look as obsolete as black-and-white MacPaint format does
today.  Furthermore, for reasons detailed in section 7, JPEG is far more
useful than GIF for exchanging images among people with widely varying color
display hardware.  Hence JPEG is considerably more appropriate than GIF for
use as a Usenet posting standard.

3)  How well does it work?

Pretty darn well.  Here are some sample file sizes for an image I have handy,
a 727x525 full-color image of a ship in a harbor.  The first three files are
for comparison purposes; the rest were created with the free JPEG software
described further on.

File	   Size in bytes		Comments

ship.ppm	1145040  Original file in PPM format (no compression;
			 3 bytes per pixel plus a few bytes overhead)
ship.ppm.Z	 963829  PPM file passed through Unix compress
			 compress doesn't accomplish a lot, you'll note.
ship.gif	 240438  Converted to GIF with ppmquant -fs 256 | ppmtogif
			 Most of the savings is the result of losing color
			 info: GIF saves 8 bits/pixel, not 24.  (See sec. 7.)

ship.jpg95	 155607  cjpeg -Q 95    (highest useful quality setting)
			 This is indistinguishable from the 24-bit original,
			 at least to my nonprofessional eyeballs.
ship.jpg75	  57995  cjpeg -Q 75    (default setting)
			 You have to look mighty darn close to distinguish this
			 from the original, even with both on-screen at once.
ship.jpg50	  38399  cjpeg -Q 50
			 This has slight defects; if you know what to look
			 for, you could tell it's been JPEGed without seeing
			 the original.  Still as good image quality as many
			 recent postings in Usenet pictures groups.
ship.jpg25	  25186  cjpeg -Q 25
			 JPEG's characteristic "blockiness" becomes apparent
			 at this setting (djpeg -b helps some).  I've seen
			 plenty of Usenet postings that were uglier than this.
ship.jpg5o	   6597  cjpeg -Q 5 -o
			 Blocky, but perfectly satisfactory for preview or
			 indexing purposes.  Note that this file is TINY.

In this case JPEG can make a file that's a factor of four or five smaller
than a GIF of comparable quality (the -Q 75 file is every bit as good as the
GIF, better if you have a full-color display).  This seems to be a typical
ratio for real-world scenes.

4)  What are good "quality" settings for JPEG?

(Note: the -Q settings discussed in this article apply to the free JPEG
software described in section 6.  Other JPEG implementations, such as Image
Alchemy, may use a completely different quality scale.)

The name of the game in using JPEG is to pick the lowest quality setting
(smallest file size) that decompresses into an image indistinguishable from
the original.  This setting will vary from one image to another and from one
observer to another, but here are some rules of thumb.

The default quality setting (-Q 75) is very often the best choice.  This
setting is about the lowest you can go without expecting to see defects in a
typical image.  Try -Q 75 first; if you see defects, then go up.  Except for
experimental purposes, never go above -Q 95; saying -Q 100 will produce a
file two or three times as large as -Q 95, but of hardly any better quality.

If the image was less than perfect quality to begin with, you might be able
to go down to -Q 50 without objectionable degradation.

If you are prepared to tolerate visible defects, and want a very small file
(say for preview or indexing purposes), a -Q setting in the range of 5 to 10
is about right.  -Q 2 or so may be amusing as "op art".

Another recommendation: when you are making a final version of an image for
posting on Usenet or archiving, specify "-o" to cjpeg.  This will make the
file a little smaller without affecting image quality; it will take longer
to do the compression, but not any longer to decompress.

5)  When should I use JPEG, and when should I stick with GIF?

As a rule of thumb, JPEG is superior to GIF for storing full-color and
gray-scale images of "realistic" scenes; that means scanned photographs and
similar material.  JPEG is superior even if you don't have 24-bit display
hardware, and it is a LOT superior if you do.  (See section 7 for details.)

GIF does significantly better on images with only a few distinct colors,
such as cartoons and line drawings.  In particular, large areas of pixels
that are all *exactly* the same color are compressed very efficiently indeed
by GIF.  JPEG can't squeeze these files as much as GIF does without
introducing visible defects.  This sort of image is best kept in GIF form.
(Incidentally, many people have developed an odd habit of putting a large
constant-color border around a GIF image.  This was nearly free in terms of
storage cost in GIF files.  It is NOT free in JPEG files.  Do yourself a
favor and don't add a border; let your viewer blank out unused screen area.)

Computer-drawn images (ray-traced scenes, for instance) are an intermediate
case.  The more complex and subtly rendered the image, the more likely that
JPEG will do well on it.

If you have an existing library of GIF images, you may wonder whether you
should convert them to JPEG.  You will lose some image quality if you do,
but the disk space savings may justify converting anyway.  (Section 7, which
argues that JPEG image quality is superior to GIF, only applies if both
formats start from a full-color original.  If you start from a GIF, you've
already irretrievably lost a great deal of information; JPEG can only make
things worse.)

Experience to date suggests that large, high-quality GIFs are the best
candidates for conversion to JPEG.  They chew up the most storage so offer
the most potential savings, and they convert to JPEG with least degradation.
Don't waste your time converting any GIF much under 100 Kbytes.  Also, don't
expect JPEG files converted from GIFs to be as small as those created
directly from full-color originals.  To maintain image quality you may have
to let the converted files be as much as twice as big as straight-through
JPEG files would be (i.e., shoot for 1/2 or 1/3rd the size of the GIF file,
not 1/4th as shown in the earlier comparisons).  A -Q setting of 85 to 95
will minimize the additional degradation caused by converting a GIF to JPEG.

6)  Where can I get JPEG software?

Free, portable C code for JPEG compression is available from the Independen

More information about the Bio-soft mailing list