Standard image file formats
Sections in this page
Digital cameras usually offer two formats for storing photos as files on memory cards or on disc: JPEG and RAW.
RAW is not a general image file format. Each camera manufacturer has a proprietary file structure (.NEF from Nikon, .CRW or .CR2 from Canon, etc). Neither is RAW an abbreviation. It is usually written in capitals to avoid ambiguity.
JPEG (usually in .JPG files) is a general standard but it is inferior to RAW for two main reasons:
- The JPEG compression algorithm is lossy
- Only 8 bits per colour channel can be stored in JPEG
We will look at the details of these two factors. We will also consider some other image file formats which are important in photography: .TIFF, .PSD, .DNG, .FITS.
JPEG (Joint Photographic Experts Group) is really the name of a compression algorithm (computational method). Data are compressed by
- Dividing the image up into 8 x 8 pixel cells
- Performing a discrete cosine transform (DCT) on each cell
- Throwing away the higher frequencies from the result. The amount discarded is tunable through a quality factor, so there is a trade off between quality and resulting file size.
Huge compression ratios can be obtained but at a cost. Results will be less sharp and have ripple artefacts, which become more and more visible as the quality factor is lowered.
JPEG files are useful as a final result, for display or distribution. But each time you edit them and resave, you lose more, even at a high quality setting.
Each manufacturer has its own algorithm for compressing and decompressing image data in such a way that nothing at all is lost. Compression factors of around 6 are typical.
One drawback is that not many applications can read the files. Photoshop and some other advanced imaging applications have plug-ins for each camera to enable RAW files to be read (download latest plug-ins from adobe.com for Photoshop). You cannot process RAW files without such an application. Fortunately GRIP does have the capability to read RAW files.
Adobe has proposed DNG (digital negative) format as a common format with a similar level of loss-less compression and is believed to be trying to persuade camera makers to use it instead of their own version of RAW. Photoshop CS2 can save and reload .DNG files.
TIFF (tagged image file format) has been around for a very long time. It can compress using the LZW algorithm but (a) this doesn't compress very much for colour photos and (b) it is subject to royalty payments to Unisys.
Uncompressed TIFF files are big (124Mb in my case, for Canon EOS 5D MkII, compared to about 20Mb for a RAW file) but many applications can read and write them and no data are lost. There are two flavours of TIFF: PC and Mac. Most applications on either platform can read and save both. We have a page explaining more about the differences.
If you want an image professionally printed you should supply a TIFF file.
The full specification for TIFF can be found on Adobe's web site.
PSD is Photoshop's native format. Compresses a little and without loss. Use this if you are working on an image using layers and want to keep them for later work, because the complete structure is saved. Big files again.
First consider how the colour of a pixel is represented:
RAW has 12 bits per channel (colour) so there are 212 = 4096 possible levels on each axis:
JPEG has 8 bits per channel so there are only 256 possible levels on each axis. Imagine them spread across the same range as the 4096 levels we had before. So the steps between levels are 16 times as big. By using JPEG you are throwing away all but (1/16)3 = 0.024% of the possible data values.
To save JPEG instead of RAW, the camera bins the pixels into the 256 slots on each axis. The slots are predetermined so that the result from a "typical" image will look pleasing when immediately printed.
A RAW image looks rather less pleasing, generally very dull, when first opened in GRIP, Photoshop or other applications. So photographers' first impressions of it are disappointing. It is necessary to do some "digital darkroom" work on it. But the important thing is that you have the full data to work with; you have not thrown away most of the data the camera collected.
NB: As from 2009 digital cameras increasingly offer 14 bits per channel. That is 214 = 16,384 distinct levels for each colour. So the RAW format now has an even greater advantage over JPEG when it comes to the amount of data collected.
This is a very different format used in astronomy for digital images. It allows 8-, 16- or 32-bit integer pixel values for each channel or 32- or 64-bit floating-point values. The latter are important for scientific uses, enabling any array of data to be respresented as an image. Furthermore there can be any number of channels. The complete specification can be found on the NASA/GSFC web site. GRIP uses 32-bit integers for accumulating images, to combine multiple exposures. Since early 2011 GRIP has been able to read and save 32-bit (integer) or 64-bit (floating-point) FITS images.