MIL_ID SrcImageBufId, | //in |
MIL_ID DestImageBufId, | //in |
MIL_ID CoefOrExpId, | //in |
MIL_INT64 ControlFlag | //in |
This function converts a single-band, Bayer color-encoded image into a 1- or 3-band image. When using a single-band buffer as the destination, the destination will be filled with the Y-component obtained from the RGB to Y conversion when the Bayer image is decoded.
Optionally, you can specify to perform gamma correction and/or white balance correction on the image if the appropriate exponents and coefficients are provided, respectively. First, gamma correction is applied to the raw RGB values of the Bayer color-encoded image. Second, white balance correction is performed on the gamma corrected RGB values. Third, the demosaicing process converts the single-band, Bayer color-encoded image to a 1- or 3-band image. Finally, color correction is performed if M_COLOR_CORRECTION is specified. Color correction can only be used with the M_ADAPTIVE algorithm.
Note that you can use MbufBayer() to automatically calculate the appropriate white balance correction coefficients. To do so, specify a Bayer color-encoded source image that in reality should be a uniform shade of gray that is not too saturated, and add M_WHITE_BALANCE_CALCULATE to the ControlFlag parameter. After converting the image and calculating the appropriate coefficients, the coefficients are written to the specified MIL array buffer and the converted image is then corrected using these automatically calculated coefficients. Alternatively, you could fill an array with custom values, and then load these values (in order) into the MIL array using MbufPut1d() or MbufPut2d(). For more information, see the Correcting the white balance of your Bayer images subsection of the Using images acquired with a Bayer color filter section of Chapter 19: Data buffers. Ensure that the image was grabbed under the same lighting conditions as subsequent source images.
Note that you cannot calculate the white balance coefficients and specify an adaptive demosaicing in the same call to MbufBayer().
For more information on Bayer color-encoded images, the conversion, and the actual equations used to perform white balance and gamma correction, see the Using images acquired with a Bayer color filter section of Chapter 19: Data buffers.
Note that if the scale of the image is changed (using MdigControl() with M_GRAB_SCALE...) to a value other than 1 prior to grabbing a Bayer image, the Bayer image will not be converted properly; some of the Bayer pattern is lost during the scaling process, rendering color recovery impossible.
When using a digitizer that supports on-board Bayer conversion, the conversion of a single-band, Bayer color-encoded image into a 1- or 3-band image can be performed using either on-board buffers, or off-board (Host) buffers. When the operation is performed using both source and destination on-board image buffers, your digitizer must be able to perform the Bayer conversion on-board; otherwise, the operation will be performed on the Host.
In addition, the Bayer operation can only be performed on-board if there is sufficient memory for the operation to complete (for example, to hold internal buffers); otherwise, the operation will be performed on the Host, and the results copied to your on-board destination buffer. This will result in a speed-decrease of the Bayer operation.
To force the Bayer operation to be performed on-board, use MdigControl(). For more information, refer to the MIL Hardware-specific Notes and the Installation and Hardware Reference for your product. Note that, when using MdigControl(), gamma correction is not available.
Specifies the identifier of the source image buffer. To achieve maximum conversion performance, the source image buffer should be an unsigned 1-band image buffer. If you specify a 3-band buffer, only the first band will be used.
This image buffer must not have a region of interest (ROI) associated with it. Using an image buffer with an ROI will cause an error.
The source buffer must be an 8- or 16-bit buffer.
The buffer's minimum size X and size Y is 2. The buffer's size X and size Y must be a multiple of 2.
The source buffer must be allocated in an on-board SDRAM memory bank (using MbufAllocColor() with M_FPGA_ACCESSIBLE).
If the source buffer is 16-bit, use MbufControl() with M_MAX to specify the maximum value in the buffer.
Specifies the identifier of the destination image buffer. The results of the white balance correction, gamma correction, and color correction are clipped, if necessary, to the maximum value of the source buffer.
For the destination buffer
|
|||||||||||||||||||||||||||||||||||||||
Value |
Description
|
MIL system-specific tooltip (†) |
|||||||||||||||||||||||||||||||||||||
M_NULL |
Specifies the destination buffer will not be used. (more details...) |
† | a | b | c | d | e | f | g | h | i | j | k | l | m | n | o | p | q | r | s | ||||||||||||||||||
MIL destination Image buffer ID |
Specifies the identifier of the destination image buffer. (more details...) |
† | a | b | c | d | e | f | g | h | i | j | k | l | m | n | o | p | q | r | s | ||||||||||||||||||
MIL system specific | |||||||||||||||||||||||||||||||||||||||
On specific boards, the destination image can also be any RGB color buffer format + M_PLANAR. |
† | a | b | e | f | g | h | i | l | m | n | ||||||||||||||||||||||||||||
The destination buffer must be allocated in an on-board SDRAM memory bank, or the Host's non-paged memory (using MbufAllocColor() with M_FPGA_ACCESSIBLE + M_HOST_MEMORY). |
† | j | |||||||||||||||||||||||||||||||||||||
The buffer's minimum size X and size Y is 2. The buffer's size X and size Y must be a multiple of 2. |
† | d |
Specifies whether white balance correction and gamma correction are performed, and the coefficients and exponents used to perform these corrections, respectively.
This parameter can be set to one of the following:
For balance and gamma
correction
|
|||||||||||||||||||||||||||||||||||||||
Value |
Description
|
MIL system-specific tooltip (†) |
|||||||||||||||||||||||||||||||||||||
M_DEFAULT |
Performs no white balance or gamma correction on the source image; only the conversion is performed. |
† | a | b | c | d | e | f | g | h | i | j | k | l | m | n | o | p | q | r | s | ||||||||||||||||||
MIL array buffer identifier |
Specifies the MIL array buffer which contains the coefficients and exponents to perform the corrections. (more details...) |
† | a | b | c | d | e | f | g | h | i | j | k | l | m | n | o | p | q | r | s | ||||||||||||||||||
MIL system specific | |||||||||||||||||||||||||||||||||||||||
The buffer must have either a 3x1 or 6x1 dimension. If a 3x1 MIL array buffer is specified, no gamma correction is performed. |
† | a | b | c | e | f | g | h | l | m | n | o | s | ||||||||||||||||||||||||||
The buffer must have a 3x1 dimension. No gamma correction is performed. |
† | d |
Specifies the Bayer pattern to use in the conversion, and whether the white balance correction coefficients will be calculated. This parameter can be set to one of the following:
For the Bayer pattern
|
|||||||||||||||||||||||||||||||||||||||
Value | Description
|
||||||||||||||||||||||||||||||||||||||
M_BAYER_BG + |
Specifies the Bayer pattern that has the top-left pixel as the blue component and the next pixel as the green component. (more details...) |
||||||||||||||||||||||||||||||||||||||
M_BAYER_GB + |
Specifies the Bayer pattern that has the top-left pixel as the green component and the next pixel as the blue component. (more details...) |
||||||||||||||||||||||||||||||||||||||
M_BAYER_GR + |
Specifies the Bayer pattern that has the top-left pixel as the green component and the next pixel as the red component. (more details...) |
||||||||||||||||||||||||||||||||||||||
M_BAYER_RG + |
Specifies the Bayer pattern that has the top-left pixel as the red component and the next pixel as the green component. (more details...) |
You can add the following value to the above-mentioned values to set whether to automatically calculate the appropriate white balance coefficients.
For white balancing the source
image
|
|||||||||||||||||||||||||||||||||||||||
Combination value |
Description
|
MIL system-specific tooltip (†) |
|||||||||||||||||||||||||||||||||||||
M_WHITE_BALANCE_CALCULATE |
Determines the 3 coefficients required to white balance the source image, and writes these coefficients into the CoefOrExpId array. (more details...) |
† | a | b | c | e | f | g | h | i | j | k | l | m | n | o | p | q | r | s | |||||||||||||||||||
MIL system specific | |||||||||||||||||||||||||||||||||||||||
This value is not supported on the FPGA, although precalculated coefficients can still be applied. |
† | j | k | p | q | r |
You can add the following value to the above-mentioned values to set whether to bit-shift the result.
For bit shifting the result
|
|||||||||||||||||||||||||||||||||||||||
Combination value |
Description
|
||||||||||||||||||||||||||||||||||||||
Indicates to shift the result by the specified number of bits. (more details...) |
|||||||||||||||||||||||||||||||||||||||
Parameters | |||||||||||||||||||||||||||||||||||||||
This parameter specifies the number of bits by which to shift the result. You can set this parameter to the following: |
|||||||||||||||||||||||||||||||||||||||
|
You can add one of the following values to the above-mentioned values to set whether to override the use of the bilinear interpolation demosaicing algorithm.
For overriding the bilinear interpolation
demosaicing algorithm
|
|||||||||||||||||||||||||||||||||||||||
Combination value | Description
|
MIL system-specific tooltip (†) |
|||||||||||||||||||||||||||||||||||||
M_ADAPTIVE + |
Specifies to use the adaptive demosaicing algorithm for the conversion process. (more details...) |
† | a | b | c | e | f | g | h | i | l | n | o | s | |||||||||||||||||||||||||
M_AVERAGE_2X2 |
Specifies to use a 2x2 neighborhood kernel to perform the demosaicing. (more details...) |
† | a | b | c | e | f | g | h | i | j | k | l | m | n | o | p | q | r | s |
You can add the following value to the above-mentioned value to set whether to perform a color correction on the image.
For M_ADAPTIVE
|
|||||||||||||||||||||||||||||||||||||||
Combination value | Description
|
||||||||||||||||||||||||||||||||||||||
M_COLOR_CORRECTION |
Specifies that a color correction is performed to further eliminate false colors. |
Header | Include mil.h. |
Library | Use mil.lib. |
DLL | Requires mil.dll. |