Demosaicing is the image processing step that reconstructs a full-color RGB value for every pixel from the single-color samples recorded by a sensor covered with a color filter array. In image processing for photography it is one of the first operations applied to RAW data, and it strongly influences fine detail, color accuracy and the presence of artifacts in the final image.
Because each photosite records only one color, about two-thirds of the color information in a finished image is estimated, not measured. Demosaicing is therefore an interpolation problem, and the quality of the algorithm decides how convincingly that missing information is filled in.
Why sensors need demosaicing
Silicon photosites measure light intensity, not color. To capture color with a single sensor, manufacturers place a color filter array (CFA) over the photosites so that each one receives only red, green or blue light. The most common layout is the Bayer pattern, a 2 x 2 tile with two green, one red and one blue filter.
Green appears twice because human vision is most sensitive to green wavelengths, which carry most of the perceived luminance detail. The table compares common CFA layouts.
| Layout | Pattern structure | Demosaicing implications |
|---|---|---|
| Bayer | 2 x 2 tile, 50% green, 25% red, 25% blue | Widely supported, well-studied algorithms |
| X-Trans | 6 x 6 tile with irregular placement | Fewer moiré problems, heavier processing |
| Quad Bayer | Bayer pattern with 2 x 2 same-color groups | Supports pixel binning and HDR modes |
| Monochrome sensor | No color filters | No demosaicing needed, no color |
How demosaicing algorithms work
The simplest approach, bilinear interpolation, estimates each missing color as the average of the nearest pixels of that color. It is fast but produces soft detail and color fringes along edges, because it averages across boundaries.
Better algorithms are edge-directed and correlation-based. They detect the direction of local edges and interpolate along them rather than across them, and they exploit the fact that color differences change more slowly than luminance in natural images. Modern methods may also use iterative refinement or trained neural networks.
| Algorithm family | Principle | Strengths and weaknesses |
|---|---|---|
| Nearest neighbor | Copies adjacent values | Very fast, blocky and colored edges |
| Bilinear | Averages same-color neighbors | Simple, soft, edge fringes |
| Edge-directed (for example AHD) | Interpolates along detected edges | Sharper, occasional maze artifacts |
| Gradient-based (for example DCB, RCD) | Weighs directions by local gradients | Good detail with fewer artifacts |
| Machine learning | Networks trained on reference images | Strong detail, high computing cost |
Many RAW processors combine demosaicing with noise reduction, because noise confuses edge detection. Performing both jointly often gives cleaner results than running them as separate steps.
Demosaicing artifacts and their causes
Because the algorithm must guess missing values, it can invent patterns that do not exist in the scene, especially in fine, regular detail near the sensor’s resolution limit. Recognizing these artifacts helps separate demosaicing problems from lens or noise problems.
| Artifact | Appearance | Main cause |
|---|---|---|
| Color moiré | Rainbow patterns in fabrics or screens | Fine repetitive detail beyond CFA sampling |
| Zipper effect | Alternating light and dark edge pixels | Interpolation across sharp edges |
| False color | Colored fringes on black and white detail | Wrong color estimate at edges |
| Maze artifacts | Labyrinth-like texture in flat areas | Edge detectors misreading noise |
| Loss of fine detail | Smeared textures | Overly cautious smoothing |
An optical low-pass filter in front of the sensor reduces moiré by slightly blurring detail before sampling. Many recent cameras omit this filter to gain sharpness, which shifts more responsibility to the demosaicing algorithm and to the photographer.
Demosaicing in the RAW workflow
Demosaicing takes place early in the processing pipeline, after black level subtraction and white balance scaling and before color space conversion, the tone curve and sharpening. In JPEG shooting the camera performs it internally; with RAW files the RAW converter chooses the algorithm.
- Black level and white balance: prepare the raw values on a linear scale.
- Demosaicing: rebuilds three color channels per pixel.
- Color matrix and profile: convert camera colors to a standard space such as sRGB or Adobe RGB.
- Tone curve, noise reduction and sharpening: shape the final appearance.
Some converters let users choose the demosaicing method for each image. Detail-preserving methods suit landscapes and architecture, while smoother methods can be better for high-ISO images, where noise misleads edge detection.
Alternatives that avoid demosaicing
A few technologies sidestep demosaicing entirely or reduce reliance on it. Pixel shift multi-shot modes move the sensor by one photosite between exposures, so each location is sampled in red, green and blue. Monochrome sensors record luminance only and avoid CFA losses, and layered sensors stack color-sensitive layers vertically, although they bring their own trade-offs in noise and color accuracy.
Explained without jargon
A camera sensor cannot see color by itself. Tiny red, green and blue filters cover its pixels, so each pixel sees only one color, like a mosaic of colored tiles.
Demosaicing is the step that fills in the missing colors for every pixel by looking at its neighbors. Good demosaicing produces sharp, natural colors, while weaker methods can create strange rainbow patterns on fine fabrics or screens.
A typical use case
A fashion photographer shoots a model in a finely woven tweed jacket with a 45-megapixel camera that has no optical low-pass filter. On the screen, the jacket shows rainbow-colored swirls that were not visible in the studio.
During RAW processing he switches to a demosaicing method designed to suppress false color and applies a local moiré reduction brush to the jacket. The colored swirls disappear while the weave texture stays visible. The client receives images with accurate fabric color, which is essential for an online clothing catalog.