Skip to content

Debayer ​

Step: Linear

Turns the raw image of a one-shot-color camera into a color image. Such a sensor records only one color per pixel, in a repeating 2×2 pattern of red, green and blue filters (the Bayer pattern). Debayering fills in the two missing colors at every pixel from their neighbors, so you get a full RGB image. Use it on an opened Bayer FITS file.

Parameters ​

ParameterRangeDefaultEffect
Bayer patternFrom file header, RGGB, BGGR, GRBG, GBRGFrom file headerThe color filter layout of the sensor. From file header reads it from the FITS header; pick one by hand if the file names none or names the wrong one.

The pattern is named by the 2×2 cell at the top-left pixel of the image as Siderea shows it: RGGB means red at the top left, green to its right and below it, and blue diagonally opposite. Siderea already accounts for FITS files storing their rows bottom-up, so the pattern from the header needs no correction.

How it works ​

Every pixel keeps the value it measured for its own color. Each missing color is the plain average of the pixels of that color in the 3×3 neighborhood (bilinear interpolation):

green at a red or blue pixel   = mean of the 4 direct neighbors
red at a blue pixel            = mean of the 4 diagonal neighbors (and vice versa)
red at a green pixel           = mean of the 2 neighbors left and right, or above and below

At the image border only the neighbors that exist are averaged. The result is a 3-channel image of the same size; the capture information of the file is kept, but the Bayer pattern is removed because the image is no mosaic any more.

When to use it ​

  • Only on data that is still a mosaic. Calibrate with darks and flats first, then debayer: dark and flat frames describe the raw sensor, not the interpolated colors.
  • If the colors look wrong (red and blue swapped, or a green cast with a checkerboard texture), the pattern is wrong. Undo and try another pattern.
  • An image that is already in color cannot be debayered; the module reports an error.