Bayer encoding is a method which allows color images to be produced with only 8-bit resolution, as opposed to the typical 24-bit (RGB) representation. By assigning each pixel either a Red, Green, or Blue value, you can use the color information in the vicinity of each pixel to specify the actual color for that pixel.
The decoding scheme is very dependent on how the CCD is manufactured. One very basic algorithm is described below, but you should contact the camera manufacturer to get a more robust decoding scheme.
The goal of these encoders is to get color information with low data throughput. On a typical 3 CCD camera, the camera outputs 24 bits per pixel - 8 bits for each color (Red, Green, Blue). With Bayer encoding, the camera instead sends out only 8 bits per pixel but alternates the colors so that the colors in a neighborhood can be used to determine the value for each color component of the pixel in question.
The output is as follows:
line 0: RGRGRGRGR....
line 1: GBGBGBGBG....
line 2: RGRGRGRGR....
line 3: GBGBGBGBG....
The reason there are more green pixels is because the human eye is more sensitive to green, so that amount of data should be maximized. For every pixel, the algorithm must determine a value for the Red, Green and Blue components. Every position contains a particular color component and is surrounded by at least two of each of the other values. A very simple algorithm for decoding involves averaging the neighboring pixels of the same color.
You want to determine the value of the pixel in line 1, column 3. The pixel in question is in the center of the following group:
And let's say these pixels have the following values:
200 50 220
60 100 62
196 58 198
The Blue component will be the center pixel value, the Green and Red components will be the average of the surrounding green and red pixels, respectively:
R = (200 + 220 + 196 + 198)/4 = 203
G = (50 + 60 + 62 +58)/4 = 58
B = 100
So the final pixel value RGB is (203,58,100). This process is repeated for each pixel in the image.
The reason this algorithm depends on the manufacturer of the CCD is that there may need to be special weightings for each color. It is not likely that in manufacturing a CCD that the pixel designated as red is not actually somewhat sensitive to green and blue. There is always some leaking of colors, and the sensitivity to each color varies depends on the manufacturing process of the sensor.
Before purchasing a camera or digital frame grabber, always check on the compatibility by checking for it in the Camera Advisor at www.ni.com/camera or contact technical support for the latest updates.