🎨 Calibration and Debayering

Pre-processing and Stacking · lesson 4 of 12 · 3 min

Pre-processing turns your dozens of light frames into a single clean image. It starts with two operations applied to each light: calibration, then, for color sensors, debayering.

Building the masters

Before calibrating, you combine each family of calibration frames into a master:

  1. the bias frames are stacked into a master bias (often by averaging with rejection);
  2. the darks are stacked into a master dark;
  3. the master bias (or the master flat dark) is subtracted from each flat, then the flats are stacked into a master flat.

Combining dozens of calibration frames reduces their own noise. A master built from too few frames would inject noise back into each light: that is why series of several dozen are recommended.

Calibrating the lights

For each light, the software then applies:

  • subtraction of the master dark (which also removes the bias);
  • division by the master flat, which corrects vignetting and dust;
  • optionally a cosmetic correction: remaining hot or cold pixels are detected and replaced by a value estimated from their neighbors.

If you have no darks, you at least subtract the master bias, and cosmetic correction takes care of the hot pixels. The result will be less clean, but usable, especially if you dithered.

Siril and DeepSkyStacker chain these operations automatically: you indicate which files are bias frames, darks, flats, and lights, and the software builds the masters and applies them.

Debayering

A color sensor (DSLR, mirrorless, or color camera) does not actually see colors. Each pixel is covered by a tiny red, green, or blue filter, arranged in a repeating pattern, the Bayer matrix. In each square of four pixels, there is one red, one blue, and two greens.

Debayering reconstructs a full color image by estimating, for each pixel, the two colors it did not measure from its neighbors. The exact pattern (RGGB, BGGR, GRBG, or GBRG) depends on the sensor; Siril usually reads it from the file header. A wrongly chosen pattern produces absurd colors, typically a very green or purple image: it is the first setting to check.

Key point: debayering is done after calibration. Darks and flats must be applied to the raw data, pixel by pixel, otherwise the corrections would be mixed between neighboring colors.

The two green pixels also explain why color images often have a green cast and green noise: we will deal with them in the next module.

A monochrome camera has no Bayer matrix: no debayering, but a series of lights per filter (red, green, blue, or narrowband filters), each calibrated with its own flats.

Key points

  • First build a master bias, a master dark, and a master flat from series of several dozen frames.
  • Each light gets the master dark subtracted, then is divided by the master flat.
  • Cosmetic correction replaces the remaining hot pixels.
  • Debayering reconstructs the colors of a color sensor, always after calibration.
  • An all-green or purple image after debayering often signals the wrong Bayer pattern.