Demosaicing (also spelled demosaicking) is the step that turns a camera sensor’s single-color measurements into a full-color photo. Most sensors measure only one color at each pixel, so for every pixel the other two colors have to be estimated from its neighbors. On a 24 megapixel sensor that means 48 million of the photo’s 72 million color values are estimates, which is why how well it is done shapes sharpness, color and artifacts.
Wondering how a sensor turns light into numbers in the first place? How image sensors work explains photosites and the color filter above them.
The usual filter layout is the Bayer pattern shown above: a repeating 2 by 2 block of one red, two green and one blue. Half the sites are green because the eye is most sensitive to green, and green carries most of the detail we see. Some cameras use a larger, less regular pattern, which needs its own demosaicing method. A few sensors skip the step entirely: a monochrome sensor has no color filter, and stacked three-layer designs record all three colors at every site.
The simplest method is plain interpolation: average the nearest sites of the missing color. It works in smooth areas such as sky and skin. It fails at sharp edges and fine detail, where the neighbors on one side are not the same as those on the other, and you get color fringes, a zipper pattern along edges, and maze-like texture. Better methods look at the local gradients first and interpolate along an edge rather than across it.
Detail finer than the filter grid itself cannot be rebuilt correctly by any method. Fine fabric, distant brickwork or a feather pattern can turn into rainbow-colored false color or moire, a form of aliasing. That is why many cameras put an anti-aliasing filter over the sensor to blur detail very slightly before it is sampled.
Seeing colored ripples in fabric or screens? Moire explains why it happens and how to remove it in the field or in editing.
Where it happens decides how much say you have:
- JPEG: the camera demosaics in a fraction of a second, along with its sharpening and noise reduction, and the result is fixed in the file.
- Raw: the file still holds one color per site. Your raw converter demosaics every time it opens the file, so a different converter, or a newer version of the same one, can give finer detail or fewer artifacts from the same raw.
- Pixel shift: the camera moves the sensor by one site between several frames so every position is measured in red, green and blue. Nothing has to be estimated, which gives cleaner color and fine detail on still subjects.
In practice: shoot raw when fine detail matters, and if a file shows color fringes along high-contrast edges or false color in fine patterns, try another converter before blaming the lens. Go easy on sharpening too, because heavy sharpening exaggerates the zipper and maze artifacts a weak demosaic leaves behind.
Curious why the same raw file looks different in your editor than on the camera’s screen? Why raw photos look different from the camera preview walks through the rest of the processing.