Skip to content

cfa_to_rgbcfa_to_rgbCfaToRgbCfaToRgbcfa_to_rgbcfa_to_rgbπŸ”—

Short descriptionπŸ”—

cfa_to_rgbcfa_to_rgbCfaToRgbCfaToRgbcfa_to_rgbcfa_to_rgb β€” Convert a single-channel color filter array image into an RGB image.

SignatureπŸ”—

cfa_to_rgb( image CFAImage, out image RGBImage, string CFAType, string Interpolation )cfa_to_rgb( CFAImage : RGBImage : CFAType, Interpolation : )void CfaToRgb( const HObject& CFAImage, HObject* RGBImage, const HTuple& CFAType, const HTuple& Interpolation )static void HOperatorSet.CfaToRgb( HObject CFAImage, out HObject RGBImage, HTuple CFAType, HTuple interpolation )def cfa_to_rgb( cfaimage: HObject, cfatype: str, interpolation: str ) -> HObject

Herror cfa_to_rgb( const Hobject CFAImage, Hobject* RGBImage, const char* CFAType, const char* Interpolation )

Herror T_cfa_to_rgb( const Hobject CFAImage, Hobject* RGBImage, const Htuple CFAType, const Htuple Interpolation )

HImage HImage::CfaToRgb( const HString& CFAType, const HString& Interpolation ) const

HImage HImage::CfaToRgb( const char* CFAType, const char* Interpolation ) const

HImage HImage::CfaToRgb( const wchar_t* CFAType, const wchar_t* Interpolation ) const (Windows only)

HImage HImage.CfaToRgb( string CFAType, string interpolation )

DescriptionπŸ”—

cfa_to_rgbCfaToRgb converts a single-channel color filter array image CFAImageCFAImagecfaimage into an RGB image RGBImageRGBImagergbimage. Color filter array images are typically generated by single-chip CCD cameras. The conversion from color filter array image to RGB image is typically done on the camera itself or is performed by the device driver of the frame grabber that is used to grab the image. In some cases, however, the device driver simply passes the color filter array image through unchanged. In this case, the corresponding HALCON frame grabber interface typically converts the image into an RGB image. Hence, the operator cfa_to_rgbCfaToRgb is normally used if the images are not being grabbed using the HALCON frame grabber interface (grab_imageGrabImage or grab_image_asyncGrabImageAsync), but are grabbed using function calls from the frame grabber SDK, and are passed to HALCON using gen_image1GenImage1 or gen_image1_externGenImage1Extern.

In single-chip CCD cameras, a color filter array in front of the sensor provides (subsampled) color information. The most frequently used filter is the so-called Bayer filter. The color filter array has the following layout in this case:

\[\begin{eqnarray*} \begin{array}{|c|c|c|c|c|c|c} \hline \rule[-1.5ex]{0ex}{4.5ex} \textrm{G} & \textrm{B} & \textrm{G} & \textrm{B} & \textrm{G} & \textrm{B} & \cdots \\ \hline \rule[-1.5ex]{0ex}{4.5ex} \textrm{R} & \textrm{G} & \textrm{R} & \textrm{G} & \textrm{R} & \textrm{G} & \cdots \\ \hline \rule[-1.5ex]{0ex}{4.5ex} \textrm{G} & \textrm{B} & \textrm{G} & \textrm{B} & \textrm{G} & \textrm{B} & \cdots \\ \hline \rule[-1.5ex]{0ex}{4.5ex} \textrm{R} & \textrm{G} & \textrm{R} & \textrm{G} & \textrm{R} & \textrm{G} & \cdots \\ \hline \vdots & \vdots & \vdots & \vdots & \vdots & \vdots & \ddots \end{array} \end{eqnarray*}\]

Each gray value of the input image CFAImageCFAImagecfaimage corresponds to the brightness of the pixel behind the corresponding color filter. Hence, in the above layout, the pixel (0,0) corresponds to a green color value, while the pixel (0,1) corresponds to a blue color value. The layout of the Bayer filter is completely determined by the first two elements of the first row of the image, and can be chosen with the parameter CFATypeCFATypecfatype. In particular, this enables the correct conversion of color filter array images that have been cropped out of a larger image (e.g., using crop_partCropPart or crop_rectangle1CropRectangle1).

The algorithm that is used to interpolate the RGB values is determined by the parameter Interpolationinterpolationinterpolation. For Interpolationinterpolationinterpolation \(=\) 'bilinear'"bilinear", a bilinear interpolation is performed. While this algorithm is very fast, it typically leads to β€œzipper-like” artifacts and color artifacts at strong edges. For Interpolationinterpolationinterpolation \(=\) 'bilinear_dir'"bilinear_dir", a modified version of the bilinear interpolation is performed that may lead to fewer zipper-like artifacts, especially at horizontal or vertical edges in the image. The results may still exhibit color artifacts at strong edges, however. The runtime of this algorithm is only slightly longer than that of bilinear interpolation. For Interpolationinterpolationinterpolation \(=\) 'bilinear_enhanced'"bilinear_enhanced", an enhanced version of the bilinear interpolation is performed that produces fewer zipper-like artifacts and color artifacts than the other two bilinear algorithms in most cases. The runtime of this algorithm is significantly longer than that of the other two algorithms.

If 'mmx_enable'"mmx_enable" is set to 'true'"true" (and the SIMD instruction set is available), the internal calculations for byte images are performed using SIMD technology for Interpolationinterpolationinterpolation \(=\) 'bilinear'"bilinear" and Interpolationinterpolationinterpolation \(=\) 'bilinear_dir'"bilinear_dir".

For Interpolationinterpolationinterpolation \(=\) 'bilinear'"bilinear" and Interpolationinterpolationinterpolation \(=\) 'bilinear_dir'"bilinear_dir", cfa_to_rgbCfaToRgb can be executed on OpenCL devices. The width of the input image should be a multiple of four for byte images, or two for uint2 images, as the operation will be much slower otherwise.

Execution informationπŸ”—

Execution information
  • Supports OpenCL compute devices.

  • Multithreading type: reentrant (runs in parallel with non-exclusive operators).

  • Multithreading scope: global (may be called from any thread).

  • Automatically parallelized on tuple level.

  • Automatically parallelized on domain level.

ParametersπŸ”—

CFAImageCFAImagecfaimage (input_object) singlechannelimage(-array) β†’ object (byte* / uint2*)object (byte* / uint2*)HObject (byte* / uint2*)HImage (byte* / uint2*)HObject (byte* / uint2*)Hobject (byte* / uint2*) *allowed for compute devices

Input image.

RGBImageRGBImagergbimage (output_object) multichannel-image(-array) β†’ object (byte / uint2)object (byte / uint2)HObject (byte / uint2)HImage (byte / uint2)HObject (byte / uint2)Hobject * (byte / uint2)

Output image.

CFATypeCFATypecfatype (input_control) string β†’ (string)(string)HTuple (HString)HTuple (string)strHtuple (char*)

Color filter array type.

Default: 'bayer_gb'"bayer_gb"
List of values: 'bayer_bg', 'bayer_gb', 'bayer_gr', 'bayer_rg'"bayer_bg", "bayer_gb", "bayer_gr", "bayer_rg"

Interpolationinterpolationinterpolation (input_control) string β†’ (string)(string)HTuple (HString)HTuple (string)strHtuple (char*)

Interpolation type.

Default: 'bilinear'"bilinear"
List of values: 'bilinear', 'bilinear_dir', 'bilinear_enhanced'"bilinear", "bilinear_dir", "bilinear_enhanced"

ResultπŸ”—

cfa_to_rgbCfaToRgb returns 2 (H_MSG_TRUE) if all parameters are correct. If the input is empty the behavior can be set via set_system(::'no_object_result', <Result>:). If necessary, an exception is raised.

Combinations with other operatorsπŸ”—

Combinations

Possible predecessors

gen_image1_externGenImage1Extern, gen_image1GenImage1, grab_imageGrabImage

Possible successors

decompose3Decompose3

See also

trans_from_rgbTransFromRgb

ModuleπŸ”—

Foundation