Raw, JPEG and Histograms
Photography Fundamentals
Course 1 · Chapter 8 · Raw, JPEG and Histograms: Files and Editing
What the Camera Saves
Most cameras let you save a picture as a JPEG, a raw file, or both. Photography Fundamentals 7 mentioned that setting white balance later is easier on raw data; this chapter explains the difference, and how to check exposure with a histogram.
Raw and JPEG Compared
Wikipedia's Raw image format article says a camera raw file "contains unprocessed data straight from a digital camera", which software (or the camera) later converts into a viewable picture. The JPEG article calls JPEG a lossy compression method: some original information is lost and cannot be restored.
| Point | Raw | JPEG |
|---|---|---|
| Bit depth | Typically 12 or 14 bits per channel (about 4,096 to 16,384 shades) | 8 bits per channel (24-bit colour) |
| Compression | Typically lossless or high-quality lossy | Lossy; adjustable quality trade-off (a 0 to 100 scale in common encoders); typically about 10:1 |
| File size | Typically 2 to 6 times larger than a JPEG | Smaller |
| White balance | Can be set to any value later | Baked in; not just a metadata choice (check) |
| Editing | Large corrections show fewer artifacts; changes are non-destructive | Quality drops each time it is re-saved |
| Opening | Needs a conversion step and possibly specialised software | Opens almost anywhere |
Counting Shades
The script below turns bits per channel into the number of shades per channel and the number of possible colours (three channels). I ran it and the output is shown. The numbers are simply powers of two; the article's 4,096 to 16,384 shades for 12 and 14 bits agree.
JPEG Habits
The JPEG article says JPEG is not well suited to files that will undergo multiple edits, because quality drops each time the file is recompressed, and recommends editing in a lossless format and producing the JPEG at the end. It describes the resulting quality loss at about 10:1 as perceptible but widely accepted as tolerable. It also notes chroma subsampling, most commonly 4:2:0, which halves colour-information resolution both horizontally and vertically.
The Histogram
A histogram, per Wikipedia's article, plots tonal values on the horizontal axis, dark on the left and light on the right, with the number of pixels at each tone on the vertical axis. A very dark image has most of its data on the left and centre; a very bright one has it on the right and centre. Photographers use it to see whether detail has been lost to blown-out highlights or blacked-out shadows (clipping). The article does not describe what clipping looks like; it appears as pile-ups at the far ends, which is my own description (check). The article also warns that the histogram is less useful for raw files, because the displayed image's dynamic range may only approximate the raw file's.
The script builds a text histogram of 16 invented pixel brightness values (0 to 255) in eight bins and counts values at the extremes. The "clipped" test here, exactly 0 or exactly 255, is a simplification of my own. I ran it.
Not Yet Verified, and Sources
- Sources. Wikipedia articles Raw image format (read to about 100,000 of 102,213 characters; the last 2,213 were not read), JPEG (about 100,000 of 221,037 characters; the rest was not read) and Histogram (photography). All were read through page summaries.
- Not on the pages read. Whether a JPEG's white balance is truly fixed, the visual signature of clipping, and the idea that bit depth is not detail (my summaries; check).
- Not tested. I did not open a real raw file or compare real files.
Exercises
Add 10 and 16 bits to the first script. Give the number of shades per channel for each, and say how many times more shades 14 bits gives than 8 bits.
For each job choose raw, JPEG, or both, with a one-sentence reason from the comparison table: (a) a rushed set of snapshots to send straight to a friend, (b) a difficult high-contrast scene you expect to edit heavily, (c) a shoot where card space is very limited.
Run the histogram script on [100, 110, 120, 130, 140, 150, 160, 170]. Give the bar heights, describe the shape, and say what kind of picture it suggests.
Quick Reference
- Raw: unprocessed data, 12 or 14 bits, bigger files, flexible edits
- JPEG: lossy, 8 bits, small, degrades on repeated saves
- DNG: open raw format from Adobe
- Histogram: dark left, light right; look for pile-ups at the ends
- Check: clipping appearance, bit depth versus detail