Bayer Transform

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.
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, but parity adjustment is unnecessary 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. There are three ways to reconstruct the missing pixels. The more complex the interpolation, the slower the conversion. However, it is highly recommended to use interpolation.

  • Non-interpolated mode: duplicates the nearest pixel to above and/or to the left of the current pixel.
  • Standard interpolated mode: averages relevant neighboring pixels.
  • Improved interpolated mode (recommended): interpolates the unknown component values. This mode reduces visible artifacts along object edges.

Converted images with no (top), standard (left) and improved interpolation method (right)