[ Home ] [ Articles ]
|Vol. 9(8), pp. 10-16||The McAllen International Orchid Society Journal||August 2008|
One of the major complications of digital photography is learning about digital image formats. There is a veritable acronym soup of formats out there. These include (in alphabetical order): BMP, GIF, JPEG, JPG, PNG, PBM, PGM, PNM, PPM, RAW, TIFF, and a whole bunch of others. Further complicating the mess are the variant spellings of the same format (for instance, JPEG and JPG refer to the same digital image standard). Unfortunately, not all digital image formats were created equal. Some have fabulous color, but are enormous. Others squeeze themselves down into the smallest possible space, but have lost their looks.
Fig. 1. Trichocentrum cebolleta (Jacq.) M.W.Chase & N.H.Williams. Original JPEG image reduced to 5% of original size and saved with JPEG quality level of 97. (The original, uncompressed image can be found here.)
This article will attempt to unravel some of this mess by looking at some of the more popular image formats and sorting out the trade-offs made. To do this, your author will be using as an example a single photo of Trichocentrum cebolleta (Jacq.) M.W.Chase & N.H.Williams (Fig. 1). This photo will be converted to other formats and otherwise manipulated to illustrate some of the features and trade-offs in image formats. (On a side note: all of the graphics manipulations in this article were done with GIMP version 2.4.5, a free image editing program that can be obtained from http://www.gimp.org/; all settings mentioned are GIMP settings.)
What is the best digital format? The only simple answer is "It depends." Depending on what you are doing -- publishing on the web, printing a photograph, storing scientific information, creating a closeup, or something else -- the best format to choose will change. However, before discussing the formats themselves, it might be best to first consider the digital photo itself.
At the most basic level, a digital photo is a long series of numbers that represent the colors of a series of points arranged on a grid. As originally downloaded from my camera in JPEG format, the photograph in figure 1 represented 10,077,696 dots of color (pixels; picture elements), arranged in 2,592 rows and 3,888 columns. Each dot of color is represented by three numbers recording the level of red, green, and blue light seen by the camera. These numbers range from 0 to 255 (8 bits) each, allowing some 16,777,216 possible colors (this scheme is known as RGB, for the red, green, and blue levels stored). Without any compression, this photo would take up approximately 30 MB of disk space. With the standard JPEG compression set by my camera, the photo actually takes up only 3 MB of space.
Different image formats basically represent different ways of storing the series of dots that make up the picture. These result from the fact that there is no one best way to store the image. Consider the 10,077,696 dots of color from the original photo depicted in figure 1. If I am going to store all of those dots, should I store them row by row or column by column? How should I tell someone who is trying to read the image how many rows and columns there are? Should I record this before the actual image data, or after? Perhaps I should store all of the red dots, then the green dots, then the blue ones. Or maybe I should store one of the blue dots, then one of the green dots, then one of the red dots, then the next blue one, and so on. Maybe I want to compress the dots with some fancy mathematics in order to reduce the amount of space taken. Which formula should I use? Should I use a formula that compresses really well, but is "lossy" (i.e., reduces image size by throwing out some data and thus lowering image quality)? Or is it important to me to have a "lossless" format that is able to decompress and restore each and every original dot? Perhaps 16,777,216 possible colors is ridiculous. Who would really be able to see them all anyway? (Or even name them.) By selecting the most important 256 colors and storing that in a color table, I can really reduce the size of my image.
These kinds of questions are why there are so many different formats. The people who designed the formats had unique needs and so came up with a myriad of answers to the questions. Here we will consider only some of the most popular modern formats.
Fig. 2. Trichocentrum cebolleta (Jacq.) M.W.Chase & N.H.Williams. Original JPEG image converted to TIFF and reduced to 5% of original size and saved with different TIFF color and compression options; these were, from left to right, black and white, grayscale, color with no compression, color with LZW compression, and color with pack bits compression. The five resulting images were stitched together and then saved in PNG for convenience (and since PNG uses lossless compression which would not further alter the images).
The Tagged Image File Format, better known as TIFF, is one of the more common image formats. It started off as a purely black and white format used with desktop scanners that allowed one to scan a text document and then fax it. Eventually it added the ability to store a range of gray and then full color (Fig. 2). As TIFF's capabilities were extended into the color realm, the size of the images grew and began to take up a lot of expensive (in the 1980s) disk space. Consequently a variety of compression schemes were added. One of these was the LZW (Lempel-Ziv-Welch) compression scheme that was "lossless", fast, but did not necessarily achieve the best compression possible. Unfortunately the need to license the LZW compression patent (now expired) meant that many popular graphics programs could not legally support the scheme at the time. This meant that images compressed with LZW were often unreadable by some programs and, therefore, it never became the standard for compression. This legal encumbrance led people to find other compression schemes like "pack bits" compression and others.
While color TIFF images are generally high quality, the size of the images (and the legal problems with LZW) made them unpopular in the web world. Especially in the days of connecting to the web via a dial-up connection, trying to download pictures that were several megabytes in size was slow and could be expensive. This drove the need to find a good compression scheme that made image files much smaller, even if the results were not perfect. Another source of unpopularity (and general user frustration) was that one could never be sure if a TIFF file produced by one program could actually be read by a different program that claimed to be able to read TIFF images -- the various compression options were not supported universally across all programs. All of this eventually led to the image format that we know as JPEG.
Fig. 3. Trichocentrum cebolleta (Jacq.) M.W.Chase & N.H.Williams. Original JPEG image reduced to 5% of original size and saved with different JPEG quality levels; these were, from left to right, 97, 74, 50, 26, and 3. The five resulting images were stitched together and then saved in PNG for convenience (and since PNG uses lossless compression which would not further alter the images). Note that the GIMP JPEG quality levels range from 100 down to 0.
JPEG images were essentially an attempt to create an image that takes up a reasonable amount of disk space and still looks good. To reduce disk space, JPEG compresses images with a "lossy" compression scheme. In other words, JPEG sacrifices a bit of the detail on the picture to do its job. In many cases, this is not noticeable to someone simply looking at the picture. However, when zooming in more closely or in cases of extreme compression, the sacrifice does create noticeable problems. For example, consider the following five reproductions of our photo, each compressed to a different level in JPEG (Fig. 3):
As you can see in this figure, the JPEG compression looks pretty good, except on the fifth image. In print (depending upon the quality of printer, paper, ink, and sizing) you might not even be able tell the difference between the first four. However, if you have a reasonably good monitor, you can go to the MIOS website (http://www.miosjournal.org) and examine the photos there; there you should be able to see the quality degrade slowly from left to right; you may need to verify that you have a modern internet browser to see all of these images -- ensure that you are running at least Firefox 2 or Internet Explorer 7.
Fig. 4. Trichocentrum cebolleta (Jacq.) M.W.Chase & N.H.Williams. Original JPEG image reduced to 5% of original size and saved as GIF. Note visible "steps" in the colors from one shade to the next.
Another image format that attempted to overcome TIFF's limitations was the Graphics Interchange Format (GIF). Basic compression used the LZW scheme (this eventually led to various legal battles over the licensing once the owners of the LZW patent realized that GIF used LZW). To reduce file sizes even further, GIF stored less color information. Instead of using the RGB scheme to store each pixel's color with three numbers representing red, green, and blue, GIF used a color table with a mere 256 possible colors. This meant that the image could display only 256 of the 16,777,216 possible color variations available with RGB. For a photograph this meant a significant loss of quality for the size reduction achieved (Fig. 4).
Fig. 5. Trichocentrum cebolleta (Jacq.) M.W.Chase & N.H.Williams. GIF image of flower with background set to transparency. On a blank page or viewed in a browser with a white background, the image background will be white as well.
Fig. 6. Trichocentrum cebolleta x Angraecum distichum. Note that this bizarre hybrid has flowers from both parents, reduced to size of normal Angraecum distichum flowers. In reality the only crossing here was digital with the transparent GIF image of Trichocentrum cebolleta placed on top of an appropriately sized image of Angraecum distichum.
Fig. 7. Trichocentrum cebolleta (Jacq.) M.W.Chase & N.H.Williams. Three possibilities here: an orchid mating dance intended to attract the pollinator; the effect of a light, variable breeze on the blossom; or, for Star Trek fans, a ripple in the space-time continuum. Simulated with an animated GIF image.
Despite the quality and legal issues mentioned above, GIF had some nice features that made it very attractive. For instance, you could indicate that certain pixels in the image should be treated as transparent (Fig. 5). This made it possible to overlay images on each other (Fig. 6); you could also use the transparency to make images appear to have round or irregular edges. Another feature was GIF animations. In a single file you could load several images and the software that displayed them would cycle through the images like frames in a movie (Fig. 7); naturally this is only visible in the web version of the article (http://www.miosjournal.org).
Fig. 8. : Trichocentrum cebolleta (Jacq.) M.W.Chase & N.H.Williams. Original JPEG image reduced to 5% of original size and saved as PNG with maximum compression.
Of all of the formats discussed here, the Portable Network Graphics format is the most modern. Like GIF, it provides "lossless" compression and the ability to set transparency. Like JPEG, the full 16,777,216 possible color variations are available. It was developed specifically for use in an internet setting and for use without any of the legal issues plaguing both TIFF and GIF. Unless you want to do things like animations, PNG is probably the best format for preserving full image quality and still compressing down reasonably well (Fig. 8). Unfortunately it is a fairly new format: not all programs read it (e.g., Internet Explorer 6 without any extensions added); very few cameras use it.
Many digital cameras will produce images in what they call RAW format -- this is the highest quality, no compromises image possible from that particular camera. Unfortunately, Canon, Nikon, and the other camera manufacturers all define RAW differently; worse, it can also vary from camera model to camera model depending upon what imaging chip is used in that camera. So, if you save images in RAW you are guaranteed to have to use the camera's software to convert images to a more portable format and, unless someone else has the same camera you do, you will be unable to share those RAW images with anyone. Unless you absolutely need the full image data for some specific scientific reason, or because you are going to do enlargements that would otherwise look grainy, or you intend to do some specialized color processing, RAW is probably not a good format to choose.
The following table summarizes key points from the previous discussion, all with reference to the original 2,592 x 3,888 figure 1:
|Format||Disk Size||Compression||Color Scheme||Web Friendly|
|GIF||3.2 MB||LZW (lossless) and color table compression (lossy).||Color Table||Yes|
|JPEG||3.1 MB||Lossy compression. This photo is the original produced by the author's camera.||RGB||Yes|
|PNG||10.1 MB||Lossless compression; GIMP PNG level 9 (the highest compression).||RGB||Yes|
|TIFF||29.5 MB||No compression.||RGB||No|
|TIFF||12.7 MB||LZW compression (lossless).||RGB||No|
|TIFF||29.7 MB||Pack Bits compression (lossless; note that the compression scheme actually made things worse in this case).||RGB||No|
After all of this discussion a reader might still ask "What is the best digital format?". It still depends. Do you want to preserve quality for aesthetic or scientific reasons? Do you want to conserve disk space (or avoid sending someone a huge image)? Do you want almost anyone to be able to use your images (and thus need to avoid formats with patents)? Do you want to publish on the web? You should be able to at least answer some of these questions now. Look at your camera and see what formats it can save in. You now know the trade off between quality and space and can decide if you want that memory stick to be able to save 500 photos or 5000. For snapshots you may decide that the ability to save more photos is better. If you are taking photos to publish somewhere and want the highest quality possible, perhaps you should save only 500 per memory stick and carry around a couple of spare sticks. On your computer, how much disk space do you have? If you have lots, why not save the highest quality with one of the lossless compression schemes?
With the ever-cheaper prices of hard-disks, the author's rule of thumb is to save images in the highest quality, non-proprietary format allowed by his camera. While a "lossless" compression format like PNG would be ideal, the best choice available on the author's camera is JPEG with the manufacturer's selected compression level. After that, it is a matter of using a program like GIMP to resize, crop, convert, recompress, and otherwise manipulate the original image into whatever is appropriate for publication (use whatever comes out of the camera), placing on a website (use PNG with maximum compression), or emailing to someone to look at (use JPEG with medium compression). For a photo, one would almost never use GIF for any reason. And TIFF would probably only be chosen if the original image is produced by the camera in TIFF.
"Comparison of graphics file formats", http://en.wikipedia.org/wiki/Comparison_of_graphics_file_formats.
"Graphics Interchange Format", http://en.wikipedia.org/wiki/GIF.
"Image file formats", http://en.wikipedia.org/wiki/Graphics_file_format.
"Portable Network Graphics", http://en.wikipedia.org/wiki/Portal_Network_Graphics.
"Tagged Image File Format", http://en.wikipedia.org/wiki/Tagged_Image_File_Format.