Calibration, colour and stars

Phase 1 of the pipeline: every frame is calibrated, turned from the sensor's colour mosaic into a colour image, and measured, before anything is aligned.

Overview Background Stretch gallery Calibration Colour mosaic Finding stars

Calibration: removing what every frame shares

Stacking cannot remove a defect that sits in the same place in every frame. Calibration subtracts and divides those defects out first, using frames taken for the purpose.

Bias, darks and flatsmaster frames

A bias frame is a zero-length exposure: the sensor's electronic offset. A dark is an exposure with the light blocked, recording the heat signal that builds up over the exposure. A flat is an exposure of an even light source, recording how the optics and dust dim parts of the field (vignetting and dust shadows). Each light is corrected as (light − bias − dark) ÷ normalised flat.

Many calibration frames are combined into one master per type with a median, so the masters themselves carry little noise. Darks are chosen to match the lights' sensor temperature, since dark current roughly doubles every 6 °C, and scaled when their exposure time differs.

Two details matter on the Origin, which ships one pre-averaged master of each. A master that is a single file is smoothed lightly (4 pixels), because smoothing it as heavily as one noisy frame erases the sensor’s real pixel-to-pixel response. And amplifier glow does not scale with exposure time: when a session was shot at a very different sensor temperature from the dark, a few lights are calibrated and the dark’s glow scale is fitted on top of the exposure ratio. On a session 11 °C colder than its dark that took 10 to 13% of the sky structure at the 32 to 64 pixel scale out of the stack.

Hot pixels, without eating starson by default

A hot pixel is one far brighter than its neighbours. So is the centre of a small, sharp star, which is the trap: on the Origin a star can be only about two pixels wide in each colour plane. OriginStack works on the raw sensor mosaic and flags a pixel that stands far above the median of its own colour plane, then keeps it if the adjacent pixels of the other colours are also raised. A hot pixel leaves its neighbours alone; starlight spills into them.

Before this rule, the hot-pixel step was clipping the peak of almost every star in every frame. Fixing it made stacked stars about 14% narrower on one session.

Robust statisticsmedian, MAD

Astronomical images are full of outliers: stars, satellites, cosmic rays. A mean and standard deviation are dragged around by them; a median and the median absolute deviation (MAD) are not. Almost every threshold in the pipeline is set in units of a robust noise estimate like this, so it adapts to each frame instead of using a fixed number.

From colour mosaic to colour image

A colour camera sensor sees only brightness. To get colour, each pixel sits under a red, green or blue filter in a repeating 2×2 pattern (the Bayer pattern, usually RGGB): half the pixels are green, a quarter red and a quarter blue. Every pixel is missing two of its three colours, and demosaicing fills them in.

Ratio Corrected Demosaicing--debayer-method rcd default

The simplest fill averages the nearest pixels of the missing colour, which blurs edges and star profiles. RCD, by Luis Sanz Rodríguez and used by Siril, RawTherapee and darktable, first decides at each pixel whether detail runs more horizontally or vertically, and interpolates along it. It then fills colour from ratios between channels rather than raw differences, since the ratio of red to green changes much more slowly across a star than the brightness does.

Against known ground truth it has lower error than the Malvar method used before on every synthetic scene tested, and on real Origin stacks it left 7 to 15% less noise per colour.

The two greenssession-constant equalisation

The two green pixels in each 2×2 block are slightly different in sensitivity, which leaves a faint checkerboard. The difference is a property of the sensor, so it is measured once per session from a handful of frames and removed from every frame in the same pass that writes the demosaiced image.

White balance--white-balance

Each frame's channels are scaled so the sky background comes out neutral. This is only a starting point: true star colour is fitted later against a catalogue (see colour calibration).

Finding and measuring stars

Stars are the reference points for nearly everything: frame quality, alignment, the sharpness model, colour calibration and the sky position. So the pipeline needs to find them reliably in noisy frames.

The matched filterstar detection

The best linear way to find a signal of known shape in random noise is to correlate the image with that shape. A star is a small round blur, so the frame (minus its local background) is convolved with a small Gaussian the size of a star, and peaks well above the local noise are stars. The background and noise are estimated on a coarse grid of cells, so a nebula or gradient does not throw off the threshold.

Validated against the established SEP and DAOStarFinder detectors on real frames, with sub-pixel centroids after a refinement pass, and about twice as fast as SEP.

Star widthFWHM

The full width at half maximum of a star's profile is the usual measure of sharpness: the seeing that night, focus and tracking all show up in it. Each frame's FWHM, star count, signal-to-noise and a sharpness score feed into which frames are kept and how much each counts.

Comparing sharpness fairlyshared stars

A stack's average FWHM depends on which stars it was measured on. When OriginStack compares two stacks, its own or another program's, it measures the same stars in both. An earlier comparison that did not was wrong by more than the difference it claimed.

Further reading

  • Sanz Rodríguez, L. Ratio Corrected Demosaicing (RCD), as implemented in RawTherapee and Siril.
  • Malvar, H. S., He, L. & Cutler, R. (2004). High-quality linear interpolation for demosaicing of Bayer-patterned color images. Proc. IEEE ICASSP.