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.

PointRawJPEG
Bit depthTypically 12 or 14 bits per channel (about 4,096 to 16,384 shades)8 bits per channel (24-bit colour)
CompressionTypically lossless or high-quality lossyLossy; adjustable quality trade-off (a 0 to 100 scale in common encoders); typically about 10:1
File sizeTypically 2 to 6 times larger than a JPEGSmaller
White balanceCan be set to any value laterBaked in; not just a metadata choice (check)
EditingLarge corrections show fewer artifacts; changes are non-destructiveQuality drops each time it is re-saved
OpeningNeeds a conversion step and possibly specialised softwareOpens almost anywhere
Raw is not a single format
The article says manufacturers use their own, typically undocumented formats, and several encrypt parts of their files. Adobe's DNG is an open, royalty-free alternative that extends TIFF 6.0. Whether your software supports your camera's raw files depends on the camera and the software (check).

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.

for bits in (8, 12, 14): print(f"{bits:>2} bits per channel: {2 ** bits:>6} shades, {2 ** (3 * bits):,} colours")
# Output 8 bits per channel: 256 shades, 16,777,216 colours 12 bits per channel: 4096 shades, 68,719,476,736 colours 14 bits per channel: 16384 shades, 4,398,046,511,104 colours
More shades is not more detail
Extra bit depth gives smoother tones and more room to brighten or darken without visible steps. It does not add resolution or sharpness. That is my own plain-language summary, not a sentence from the article (check).

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.

def histogram(values, bins=8, top=255): counts = [0] * bins for v in values: counts[min(bins - 1, v * bins // (top + 1))] += 1 return counts pixels = [0, 0, 5, 30, 60, 90, 120, 128, 140, 180, 200, 230, 255, 255, 255, 255] h = histogram(pixels) for i, c in enumerate(h): print(f"{i * 32:>3}-{i * 32 + 31:<3} {'#' * c}") print("clipped shadows:", pixels.count(0), "clipped highlights:", pixels.count(255))
# Output 0-31 #### 32-63 # 64-95 # 96-127 # 128-159 ## 160-191 # 192-223 # 224-255 ##### clipped shadows: 2 clipped highlights: 4
Reading the example
The tallest bars are at the two ends: four pixels in the darkest bin and five in the brightest, with four exactly at 255. This mimics a high-contrast scene where highlights have been blown out. Reducing exposure (Photography Fundamentals 6's negative compensation) would shift the pile-up away from the right edge.

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

Exercise 1

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.

Exercise 2

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.

Exercise 3

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
Coming next
Photography Fundamentals 9 looks at genres of photography and what each demands of the settings you now know.