Bayer Conversion

Code Snippets

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.

BayerPattern TrueColorPattern

Bayer vs. true color format

- 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 a Open eVision ROI.

The Bayer conversion method EasyColor.BayerToC24 transforms an image captured using the Bayer pattern and stored as a gray-level image, into a true color image. That process is also known as demosaicing.

Along with the gray-level input image, the Bayer configuration is mandatory.

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

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

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

Mode 0
No interpolation
Frame rate: 943

    

Mode 1
Linear interpolation on a 3x3 kernel
Frame rate: 2159

    

Mode 2
Advanced interpolation on a 3x3 kernel
Frame rate: 1303

    

Mode 3
Interpolation on a 5x5 kernel
Frame rate: 449

    

Mode 4
Interpolation on 9x9 kernel
Frame rate: 22

    

Mode 5
Linear interpolation on 2x2 kernel
Frame rate: 950

    

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

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