30

Camera Color

A camera sensor is colorblind. It counts photons - brightness only - and yet a photo comes out in full color. Between those two facts is a clever pipeline: a grid of tiny color filters, an algorithm that guesses the missing colors, a white-balance correction, and a matrix that turns the sensor's quirky response into real color. This is the interactive tour from photons to pixels.

Digital · 42 4 Live Demos ~35 min read Sensor to image
RGGB
Bayer color filter array
demosaic
Reconstruct full color
3×3
Camera color matrix
raw
Editable, recoverable color
01

The sensor sees no color

A digital sensor is a grid of light buckets. Each photosite counts photons and reports a single number - how much light, not what color. On its own a sensor would only ever produce a grayscale image. To capture color, the camera puts a color filter over each pixel so that pixel responds to only red, only green, or only blue light. Color, in a camera, is reconstructed from a mosaic of single-color measurements - not measured directly.

That single design choice - filter, then reconstruct - ripples through everything: why files need demosaicing, why white balance is a set of gains, why a color matrix exists, and why raw preserves so much more than JPEG. The rest of the article follows the data from photosite to finished pixel.

The core trade: rather than three sensors (one per color, splitting the light), consumer cameras use one sensor with a filter mosaic and compute the missing colors. Cheaper and smaller - at the cost of needing clever processing to undo the mosaic.
02

The Bayer array and demosaicing

The dominant filter pattern is the Bayer array: a repeating 2×2 tile of one red, two green, one blue (RGGB). There are twice as many green sites because our eyes are most sensitive to green and it carries most of the luminance detail. The sensor's raw output is therefore a mosaic - each pixel holds just one channel. Demosaicing reconstructs the full image by interpolating the two missing channels at every pixel from its neighbors.

Interactive 01 · Mosaic to image

Filter the scene, then reconstruct it

The same scene in three states. Scene is the full-color truth. Bayer mosaic is what the sensor actually records - every pixel keeps only its filter's color, so it looks like a grid of red, green, and blue dots. Demosaiced interpolates the missing channels back to full color. Zoom is pixelated so you can see the mosaic.

Scene - the full-color image before the color filter array.
03

White balance from raw

The raw sensor data is not white-balanced - under warm light the red channel reads high and blue low, and vice versa. White balance in a camera is simply a set of per-channel gains (usually scaling red and blue relative to green) that make a neutral object read equal across channels. Because raw stores the data before these gains are baked in, you can set white balance freely after the fact with no quality loss.

Interactive 02 · WB gains

Neutralize the cast with R and B gain

The raw image carries a color cast from the light. Adjust the red and blue gains (green is the reference) until the gray card reads neutral - equal R, G, B. This is exactly what a camera's white balance does, and on a raw file you can redo it anytime.

Gray card: 150, 120, 90
04

The camera color matrix

Even white-balanced, the sensor's raw RGB is not "real" color - the filter sensitivities do not match human cones, so colors come out dull and slightly off, with channels that overlap differently than our eyes. A color matrix (a 3×3 transform, part of the camera's color profile) maps the camera's native response into a standard space like sRGB or a profile connection space. This is the step that turns flat sensor data into accurate, saturated color - and why two cameras need different profiles.

Interactive 03 · Color matrix

From muddy sensor response to true color

On the left is the white-balanced but uncorrected sensor color - desaturated and slightly green-biased, as raw often looks. Drag the matrix strength to apply the camera's color correction; the right panel snaps to accurate, properly saturated color. This is the camera profile doing its job.

Raw sensor color

Native response - dull, slightly green-biased.

After color matrix

Mapped to a standard space - accurate, saturated.
05

Raw vs JPEG

A JPEG is a finished photo: the camera has already demosaiced, white-balanced, applied the color matrix and tone curve, sharpened, and compressed to 8 bits - all decisions baked in. A raw file stores the high-bit sensor data with those steps recorded as editable instructions. The biggest practical payoff is highlight recovery: a raw file often holds detail in bright areas that look pure white in the JPEG, because the JPEG has already clipped them to 255.

Interactive 04 · Highlight recovery

Pull back the exposure: what survives?

Both frames are overexposed at the top. Drag the exposure recovery down. The JPEG already clipped its brightest pixels to white, so they stay flat gray - the detail is gone. The raw kept the headroom, so the same recovery reveals the gradient that was there all along.

JPEG (clipped)

Highlights baked to white - nothing to recover.

Raw (headroom)

Highlight detail preserved - recovers cleanly.
06

The full capture pipeline

Putting it together, light becomes a finished color image through a fixed chain - whether the camera does it instantly for a JPEG or you do it later from raw.

1 · Photons → charge
Each photosite, under its color filter, counts light and reports one linear value.
2 · Black level & linearize
Subtract sensor noise floor; the data is linear light at this stage.
3 · White balance
Per-channel gains so neutrals read neutral under the scene light.
4 · Demosaic
Reconstruct the two missing channels at every pixel from neighbors.
5 · Color matrix
Map camera-native RGB to a standard space via the camera profile.
6 · Tone, gamma, output
Apply a tone curve, encode to a gamma space, sharpen, and save - baked for JPEG, editable for raw.
"A JPEG is the camera's opinion, rendered once and frozen. A raw file is the evidence, kept so you can render your own opinion later - and change your mind." Editorial summary · capture as the start, not the end
07

Practical guide

If you want… Do this
Maximum color/edit latitude Shoot raw; set white balance and tone in post, non-destructively.
To recover bright skies / windows Expose to protect highlights and recover from raw, not JPEG.
Accurate color from a camera Use a proper camera profile (color matrix), not a generic one.
Consistent color across cameras Profile each camera (or shoot a color target) and convert to a common space.
Smaller files, instant sharing JPEG/HEIF is fine - just accept the baked-in decisions.
Clean edges without color fringes Rely on good demosaicing; avoid extreme sharpening that exaggerates artifacts.
08

Pitfalls and gotchas

"The sensor captures color"
It captures brightness through filters; color is reconstructed by demosaicing. The mosaic is the real data.
Editing a JPEG like raw
JPEG already baked WB, color, and 8-bit tone. Heavy edits band and can't recover clipped highlights.
No camera profile
Without the right color matrix, raw looks dull and off. Use the camera's profile or a target.
Trusting the JPEG white balance
A baked wrong WB is hard to undo in JPEG. Raw lets you reset it losslessly.
Over-sharpening
Aggressive sharpening amplifies demosaic artifacts into colored fringes and zippered edges.
Forgetting raw is linear
Raw values are linear light; they need a tone curve and gamma before they look right. Don't judge unprocessed raw.
09

Test your understanding

Six questions on the Bayer array, demosaicing, white balance, and raw. Instant feedback, no scores recorded - a wrong answer comes with a short explanation.

Quick check

Loading…
 
Question 1 of 6
10

Continue your journey

Capture is the front of the pipeline whose later stages this library covers. The numbers reflect each article's position in the editorial roadmap.