bayer
Top  Previous  Next

bayer ( integer Input, integer Output, integer Layout, [integer Mode =0, integer Rmin, integer Rmax,
integer Gmin, integer Gmax, integer Bmin, integer Bmax ] )

Use this function to convert an 8-bit color filter array image into a 24-bit RGB image.

CFA images are usually generated by a single-chip CCD camera, which has a color filter mosaic array installed in front of the sensor. The most frequently used Bayer pattern has the following layout:

G
B
G
B
B
R
G
R
G
R
G
B
G
B
G
R
G
R
G
R
     

Each pixel value in a CFA image corresponds to the intensity of the pixel behind the corresponding color filter. The conversion from such a grayscale image to RGB image is typically done on the camera itself, however some cameras (known as Bayer cameras) pass a CFA image to the framegrabber unchanged. The bayer function transforms such an image into RGB image by performing the Bayer color reconstruction (demosaicing).

Parameters
 
Input  
 
An integer between 0 and 116 specifying the input image frame number. A value of 0 represents the DMA memory buffer of the video device. Values in the range of 100-116 correspond to hidden frames.  
 
Output  
 
An integer between 1 and 116 specifying the output image frame number. Values in the range of 100-116 correspond to hidden frames.  
 
Layout  
 
An enumerated integer that defines the layout of the CFA matrix. Must be one of the following values:  
 
CAF_GB=0 – top left corner of the input image starts with a green pixel followed by a blue one.  
CAF_GR=1 – top left corner of the input image starts with a green pixel followed by a red one.  
CAF_BG=2 – top left corner of the input image starts with a blue pixel followed by a green one.  
CAF_RG=3 – top left corner of the input image starts with a red pixel followed by a green one.  
 
Mode  
 
An optional enumerated integer that describes the interpolation mode to use. Must be one of the following values:  
 
M_NONE=0 – no interpolation is performed. Missing pixels are substituted with the adjacent pixels of the same color.  
M_BILINEAR=1 – calculate the values of missing pixels by performing bilinear interpolation of the adjacent pixels.  
M_HUE=2 – calculate the values of missing pixels by performing the interpolation based on the smoothing of the hue of the adjacent pixels.  
 
Default value: CAF_NONE  
 
Rmin, Rmax, Gmin, Gmax, Bmin, Bmax  
 
Integers between 0 and 255 specifying the minimum and maximum gain level for each color component. The specified dynamic range of each component will be mapped to the full dynamic range of an RGB image. That allows for compensation of uneven sensitivity of the red, green and blue pixels in the CFA matrix. If these parameters are omitted, no scaling will be performed. If only three parameters are submitted, they will be treated as maximum levels of the Red, Green and Blue components respectively with corresponding minimum values set to zero.  
 
Error flags

ERR_OK  
 
The flag set if successful.  
 
ERR_FAILED  
 
The flag set if failed.  
 
Example

This script continuously grabs a CFA image from a Bayer camera, converts it into the RGB format and displays the resulting color image in a frame #1.  
do  
  grabIm (100)  
  bayer (100, 1 ,CFA_GR, M_BILINEAR, 0, 123, 0, 202, 0, 205, 0)  
loop