Why do black-and-white stripes come out in colour?
In the capture article, the Bayer sensor recorded one code per position. The image signal processor (ISP) has to produce three colour components at that position. On the one-pixel stripes of our Colour test chart, the samples used to fill in those missing components can come from opposite sides of an edge.
Put the RAW codes on a light scale
The ISP needs to know which filter sits at each position, which code represents darkness and where the usable signal saturates. In DNG, for example, an optional linearisation table converts the stored codes to a scale proportional to light before black subtraction. For a single black level, subtract it and divide by the difference between the saturation and black levels. On that sensor scale, 0 means darkness and 1 means sensor or readout saturation. In the stripe example, 864 is the code for chart white, which we use as the reference for the preview.
Reconstruct one pixel
Start by subtracting the black reference of 64 from the RAW codes. A photosite on chart white now reads 800 and one on chart black reads zero. The marked photosite in row 2, column 2 has a blue filter. In the original alignment it sits on black. Its blue component is measured, so we keep zero.
To estimate the missing components, use bilinear demosaicing. Average the four green neighbours above, below, left and right. Two sit on white and two on black, so the estimate is 400. Average the four red neighbours on the diagonals. All four sit on white, so red comes out as 800.
Choose Trace channel to see the exact samples in the average. Select Blue to highlight the measured value at the outlined site.
| Row | Column 1, White | Column 2, Black | Column 3, White | Column 4, Black |
|---|---|---|---|---|
| 1 | R 800 | G 0, contributes to G | R 800 | G 0 |
| 2 | G 800, contributes to G | B 0, photosite used in the reconstruction | G 800, contributes to G | B 0 |
| 3 | R 800 | G 0, contributes to G | R 800 | G 0 |
| 4 | G 800 | B 0 | G 800 | B 0 |
The outlined pixel on the black stripe is reconstructed as amber. Before shifting the stripes by one photosite, predict what happens to each component. After the shift, the outlined site measures 800 in blue. The red estimate falls to zero and green stays at 400, giving sky blue. The preview divides the signals by 800 and encodes these ideal RGB values for sRGB display.
A defective photosite can also contaminate several reconstructed pixels through the same averaging. Correcting its sample in the mosaic keeps the error out of neighbouring estimates.
From one pixel to a false-colour pattern
Start with Bayer and 1 photosite. White and black repeat every two columns, just like the red and blue sampling positions. Every red site sees white and every blue site sees black. This is spatial aliasing. From the red measurements alone, the stripes could also be a uniform white field. Shift the pattern and the two channels swap their readings.
With Bayer still selected, set Stripe width to 8 photosites. All three estimates agree inside each stripe. False colour clusters near the edges, where the reconstruction mixes measurements from opposite sides. An edge-aware estimate can use samples from the same side where they exist.
Return to 1 photosite and switch Colour-filter mosaic. Quad Bayer and X-Trans place red and blue sites on both kinds of stripe. Compare the counts below Measured samples, then look for the different patterns of false colour in Reconstructed RGB.
All three layouts keep the measured value at each site. For each missing channel, they average the samples of that colour tied for closest. The comparison uses sharp stripes and ideal filters, and reads Quad Bayer at full resolution. In a camera, optical blur or a low-pass filter can reduce stripe contrast before sampling.
From camera RGB to an image you can edit
Imagine photographing a neutral grey card and a red patch beside a bright window. After demosaicing, every pixel already has an R, G and B value. Those numbers still describe the responses of this camera’s filters. To make a working image, we first account for the light in the room and then express the colours in a known RGB space.
White balance sets the neutral reference. Under warm light the grey card might give camera RGB (0.40, 0.32, 0.20). Multiplying the channels by (0.80, 1.00, 1.60) gives (0.32, 0.32, 0.32). Apply those same gains to the whole image, including the red patch.
Colour calibration
A grey card helps set white balance. A colour chart shows how the camera reads other colours under the same light. With both gains at 1×, the grey patches in Camera preview are neutral, but the red patch looks duller than the reference. The numbers from the camera’s filters mean something different from the same numbers in linear sRGB. The colour matrix uses all nine patches to translate between the two.
Select Mid grey on any chart and lower Red gain. The middle patch takes on a cyan cast as its red reading falls. The right-hand patch stays grey because the example fits a new matrix to the changed readings. Watch the weight on camera R below the charts.
How we fit the colour correction matrix
The matrix has nine weights. Each row tells the processor how much of the camera’s R, G and B readings to add or subtract to get one working RGB channel.
Match each camera patch to the reference in the same position. To get the first row, fit three input weights that minimise the sum of squared errors between the calculated and reference red values across all nine patches. Repeat for green and blue to get the other two rows.
| Output | R input | G input | B input |
|---|---|---|---|
| R | 1.20 | −0.10 | −0.10 |
| G | −0.10 | 1.20 | −0.10 |
| B | 0.00 | −0.20 | 1.20 |
For the selected red patch, the first row gives working red. 1.20 × 0.560 + (−0.10) × 0.200 + (−0.10) × 0.160 ≈ 0.636. The calculation uses the full precision of the fitted weights.
At 0.50× red gain, the camera’s red readings are half their values at 1.00×. The weights in the R input column double, so their contributions stay the same. The weight for working red goes from 1.20 to 2.40. The corrected chart matches the reference exactly here because the simulated error and the gain change can both be undone by a matrix, and the readings never clip.
Build a profile, then use it on photographs
To build a profile, photograph a known colour chart under even, controlled lighting. Use linear RAW-derived readings and keep the patches below clipping. Pair each reading with a reference colour for that light, from the chart’s published measurements or from a measurement of the patch. A single matrix usually matches real patches only approximately. To learn how well it works on other colours, check patches that were left out of the fit.
The sandbox repeats that fit as you move the sliders because it has the chart and its reference values. For a regular photograph, the ISP or RAW editor applies a profile built for that camera and appropriate to the lighting. The colour transform acts on every pixel. The table below uses the sandbox’s starting gains (1×), where the neutral card stays grey and the red patch gets new values in linear sRGB.
| Patch | Camera RGB | After white balance | Working RGB |
|---|---|---|---|
| Neutral card | R 0.400G 0.320B 0.200 | R 0.320G 0.320B 0.320 | R 0.320G 0.320B 0.320 |
| Red patch | R 0.700G 0.200B 0.100 | R 0.560G 0.200B 0.160 | R 0.636G 0.168B 0.152 |
Edit in linear light
The Working RGB column shows values from the scene-linear working image. Those values are proportional to the captured light within the linear range. An extra stop of exposure in the editor doubles the grey card’s (0.32, 0.32, 0.32) to (0.64, 0.64, 0.64). The same edit takes two neutral areas of the window from 0.60 and 0.80 to 1.20 and 1.60. The working image keeps both values. This multiplication happens after capture, so the edit leaves the original RAW codes intact. The colour models article compares this arithmetic with editing encoded values.
From the working image to a photograph you can view
Return to those two areas of the window. Values 1.2 and 1.6 belong to the edited working image. On the separate display-linear scale, 1 means the brightest white. Clipping caps every value above that limit at 1. Both window areas become the same white, so the output loses the detail that their difference carried.
Rendering chooses how the photograph will look. In this example, tone mapping fits the brightness range to the display. The highlight curve maps the window values to 0.792 and 0.844, so the two areas remain distinguishable. For neutral tones it keeps values through 0.5 and applies T(x) = 1 − 1/(4x) above 0.5. Rendering also fits colours to the range the output can represent, called its gamut.
Transfer encoding then turns those display-linear values into numbers to store. For an 8-bit sRGB photo the two window values become codes 230 and 237. The viewer interprets these codes using the image’s colour space and sends the result to the display. The sRGB encoding curve below maps each display-linear component L to a signal E.
- sRGB transfer function. At 0.50 display light, the encoded signal is about 0.735, or code 188 in full-range 8-bit RGB. Writing the linear value directly as code 128 makes the viewer decode it to about 0.216 light, so the swatch gets darker.
- Highlight tone curve. Try the two edited window values, 1.2 and 1.6. The tone-curve swatch changes from code 230 to 237. The hard-clip swatch stays at code 255.
- BT.709 and sRGB. At a normalised input of 0.50 the curves give 0.706 and 0.735, respectively. The shared axis compares their shapes. The BT.709 opto-electronic transfer function (OETF) maps linear source values to a video signal. In this example sRGB takes display-linear light. At playback the display’s electro-optical transfer function maps the interpreted signal to emitted light.
The final code is rounded to a finite set of levels. On a smooth ramp, several successive inputs can round to the same code and then jump together to the next one. That produces banding when the steps become visible. The slope of the encoding curve controls how widely those steps are spaced in linear light. Clipping flattens an entire range above a ceiling. Quantisation creates many small plateaus across the range.
The same camera capture can give you a RAW file to develop or a ready-to-view JPEG. A RAW editor reconstructs a working image and renders a preview as you adjust it. On export, it renders and encodes the edited result for the chosen output. A camera that saves a JPEG makes those rendering choices in-camera. If both areas of the window were clipped to the same white in the JPEG, darkening that JPEG would still leave them identical. Starting from the RAW data can preserve their difference if the sensor captured it.
Video workflows can also hand off at these points:
- RAW mosaic. Save the samples and metadata for a RAW processor.
- Working image. Keep scene-relative colour for further processing. A video camera may record scene-relative values with a log curve. An input transform can convert that recording to the grading space.
- Rendered output. Encode a still for the intended display, or prepare video for the encoder. In a conventional SDR video path, the ISP can convert encoded R′G′B′ to luma and colour-difference components (Y′CbCr). Transfer function, primaries and code range tell the receiver how to interpret the values. The Encoder colour article shows how those components are sampled and stored.
References
- Adobe, Digital Negative specification, Chapter 5
- Malvar, He and Cutler, High-Quality Linear Interpolation for Demosaicing of Bayer-Patterned Color Images
- Cornell CS6640, Digital camera photofinishing pipeline
- ACES, Input Transforms
- Akkaynak et al., Colour calibration with a reference chart, equations 6–8
- ACES, Capturing a colour chart for an input transform
- ACES, Rendering and Display Encoding
- ICC, sRGB colour space and transfer function
- ITU-R BT.709, HDTV signal parameters