Bayer Conversion

The Bayer pattern is a color image encoding format for capturing color information from a single sensor. A color filter with a specific layout is placed in front of the sensor so that some of the pixels receive red light only, while others receive green or blue only. That filter is also named Color Filter Array or CFA.

An image encoded by the Bayer pattern has the same format as a gray-level image and conveys three times less information. The true horizontal and vertical resolutions are smaller than those of a true color image.

Bayer format.
True color format.

Hint

  • The Bayer pattern normally starts with a GB/RG block in the upper left corner.

  • If the image is cropped, this parity rule can be lost.

  • Parity adjustment is not necessary when working on an eVision ROI.

The Bayer conversion method EasyColor::BayerToC24 .NET Python transforms an image captured using the Bayer pattern and stored in a gray-level image, into a true color image. That process is also known as demosaicing. The Bayer configuration is supposed to be known and should be specified during the conversion.

There are 4 different arrangements of the Bayer pattern, defined by the first 2 pixels of the first row of the image:

List of available arrangements of the Bayer pattern.

When the first pixels of the first row are:

Several methods are available to reconstruct the missing pixels.

  • Some are fast but the resulting image may have artifacts, like the zipper effect or color aliasing.

  • Some are slower but achieve better interpolation and produce less artifacts.

Interpolation Modes

Interpolation modes can be specified using the last argument of the EasyColor::BayerToC24 .NET Python. Correct values are:

  • 0: Copy, no interpolation

  • 1: Bilinear, linear interpolation on 3x3 kernel

  • 2: Median, advanced interpolation on a 3x3 kernel

  • 3: Gradient based, interpolation on a 5x5 kernel

  • 4: Error minimization, interpolation on 9x9 kernel

  • 5: Average, linear interpolation on 2x2 kernel

The frame rate is given for the conversion of a 1280 x 720 image on a single core Intel i7-12800 CPU.

  • Mode 0 (No interpolation)

    • Frame rate: 2.263ms (441 FPS)

Input image.
Result with no interpolation.
  • Mode 1 (Linear interpolation on a 3x3 kernel)

    • Frame rate: 0.966ms (1035 FPS)

Input image.
Result with bilinear interpolation.
  • Mode 2 (Advanced interpolation on a 3x3 kernel)

    • Frame rate: 1.089ms (918 FPS)

Input image.
Result with median interpolation.
  • Mode 3 (Interpolation on a 5x5 kernel)

    • Frame rate: 20.393ms (49 FPS)

Input image.
Result with gradient-based interpolation.
  • Mode 4 (Interpolation on 9x9 kernel)

    • Frame rate: 84.370ms (11 FPS)

Input image.
Result with error minimization interpolation.
  • Mode 5 (Linear interpolation on 2x2 kernel)

    • Frame rate: 0.815ms (1227 FPS)

Input image.
Result with average interpolation.

The method EasyColor::C24ToBayer .NET Python is the reciprocal function of EasyColor::BayerToC24 .NET Python. It converts RGB color pixel images to Bayer images using the given EBayerConfiguration .NET Python.

A Bayer encoded image is not compatible with a true color image (EImageC24 .NET Python), but you can apply white balance and gamma correction with the EColorLookup .NET Python parameter in EasyColor::TransformBayer .NET Python.

See Also

Code Snippets

Easy to understand, ready to copy code snippets.

EasyColor