Working with Color ImagesCognex VisionPro

The VisionPro acquisition system can acquire a wide variety of pixel formats including Grey8, Grey10, Bayer8, and others. Each video format will output a specific pixel format which you can convert by setting the OutputPixelFormat property. If the OutputPixelFormat property you specify requires no conversion, no conversion will take place and no time is wasted.

Pixel formats refer to how information associated with each pixel is stored in memory. VisionPro supports color acquisition for the following three pixel formats.

  • RGB Planar format. This is the standard color format for VisionPro color vision tools. This format is an image with three 8-bit planes: Red, Green and Blue. If this option is used with a grey-scale camera, each of the three planes (R, G, and B) are identical and each contains the grey-scale image.
  • Grey 8 format. When you use this format the image from the camera is converted to an 8-bit grey-scale image. Grey-scale images are required for most Cognex vision tools.
  • Raw format. This format is only available for color cameras that output the Bayer color format, and the acquired image is retained in the Bayer format. If you choose to work with the Bayer format you will have to convert it to RGB Planar or Grey 8 format if you want to use it with Cognex vision tools. Use the CogImageConvert tool to make this conversion.

Cognex vision tools can only accept images with RGB or Grey8 pixel formats. If the acquired image is not one of these formats, you should use the OutputPixelFormat property to have the acquisition stream convert it for you.

Color Image Objects

For RGB Planar format VisionPro includes the CogImage24PlanarColor class. This type of image includes three 8-bit image objects, each representing one of the three planes of a planar color image. For the Grey 8 format the CogImage8Grey class is provided. This class describes a rectangular array of 8 bit grey scale pixels. Although Raw is a color format, it"s color data is stored in the CogImage8Grey class.

Acquiring Color Images

To acquire color images, you must use a frame grabber and a camera that support color acquisition such as the Cognex MVS-8504 and the Sony DCX-390 camera, an MVS-8600 supported color camera, or a supported IEEE 1394 DCAM-compliant color camera. Color acquisition is similar to grey-scale acquisition except that you must specify a color camera format.

See Camera Acquisition for information on how to acquire color images using QuickBuild. See Acquiring Color Images for an acquisition code example.

Color Image Tools

This section contains the following subsections.

The following tools operate directly on color images:

  • Image File Tool
  • Copy Region Tool
  • Image Convert Tool
  • Color Image Display
  • Color Segmenter Tool
  • Simple Color Match Tool
  • Composite Color Match Tool
  • Checkerboard Calibration Tool

Also, the acquisition stream in QuickBuild automatically converts Bayer images to RGB format during acquisition.

The following paragraphs provide a short description of each tool.

Note: Your Microsoft Windows desktop must be set to 16-bit or 32-bit color to display color images using VisionPro.

Image File Tool

You can Open 24-bit color bitmap (BMP) files and 24-bit color TIFF (TIF) files with the CogImageFileTool. A 24-bit TIFF image must consist of three 8-bit planes. You can open bitmap (BMP) files of other depths; 1-bit, 4-bit, 8-bit, and 24-bit, but they will be converted to grey-scale. (Note that 16-bit and 32-bit BMP files are not supported). Color TIFF files that are not 24-bits deep are not converted.

Copy Region Tool

The CogCopyRegionTool works with both color images and grey-scale images.

Image Convert Tool

The primary purpose of the CogImageConvertTool is to convert color images to grey-scale images.

Color Image Display

To display color images, you simply supply an RGB-format CogImage24PlanarColor image to the Image property of a CogDisplay control.

When a CogDisplay status bar is associated with a color image, it automatically displays the R, G, and B values of the pixel under the mouse pointer instead of displaying a grey scale value.

Color Segmentation Tool

Maps regions of color space into grey scale images that can be processed using most Cognex vision tools.

Simple Color Match Tool

Compares the average color in a color image ROI to the average color of the same ROI in a trained model. The output is a score in the range 0 through 1.

Composite Color Match Tool

Compares the color distribution in a color image ROI to the color distribution of the same ROI in a trained model. The output is a score in the range 0 though 1.

Checkerboard Calibration Tool

The CogCalibCheckerboardTool will accept CogImage24PlanarColor or CogImageGrey8 checkerboard images for calibration, but requires a grey-scale image for training.

Color Conversion Functions

This section contains the following subsections.

VisionPro includes a CogImageConvert application object that implements a number of routines for converting between different image formats. Since the CogImageConvert object is an application object, you do not need to instantiate the object to use its functions.

Note: Some cameras, such as the Basler A602fc, acquire Bayer-format images. These images must be converted to grey-scale or planar color images before you can use them.

Planar Image Conversion Functions

The GetHSIImage function accepts a RGB-format planar image and generates the corresponding HSI-format planar image. The GetIntensityImage function generates an 8-bit intensity plane image from a supplied RGB-format planar image.

In addition to the conversion functions provided by the CogImageConvert application object, the CogImage24PlanarColor object also offers a GetPlane function returns any single plane (R, G, or B from an RGB-format image or H, S, or I from an HSI-format image) as a CogImage8Grey image.

Bayer-Format Image Conversions

Before you can make any use of a Bayer-format color image, you must either convert it to an 8-bit grey scale image or to a 24-bit planar image. An unprocessed ("raw") Bayer-format image is not useful for display or image processing.

Bayer-to-Planar Conversion

The GetRGBImageFromBayer function converts a raw Bayer-format image, which in this release must be of type CogImage8Grey, into an RGB-format 24-bit planar image. You can specify a subregion of the Bayer-format image for conversion.

The GetHSIImageFromBayer is a convenience function that calls GetRGBImageFromBayer internally, then uses the planar image conversion functions described below to produce a planar image in the HSI space.

Both GetRGBImageFromBayer and GetHSIImageFromBayer take three parameters (RedWhiteBalanceScale, GreenWhiteBalanceScale, and BlueWhiteBalanceScale) that let you adjust the white balance of the converted image.

Bayer-to-Intensity Conversion

The GetIntensityImageFromBayer produces a single 8-bit intensity image from a supplied Bayer-format image. This function requires much less time than is required to produce an HSI-format planar image.

GetIntensityImageFromBayer takes three parameters (RedGreyscaleWeight, GreenGreyscaleWeight, and BlueGreyscaleWeight) that let you adjust the white balance of the converted image.

Using Color Images with Grey-scale Vision Tools

Most VisionPro vision tools do not support color images directly. To use these vision tools with a color image, you must either convert the color image to grey-scale or work with only one color image plane. For example, the following is how you might use the Blob Tool with a color image:

Dim aImgFile As New CogImageFile
Dim aImgGeneric As ICogImage
Dim aImg8 As CogImage8Grey

Dim myBlobResults As CogBlobResults
Dim myBlob As CogBlob = New CogBlob

aImgFile.Open("c:\color.bmp", CogImageFileModeConstants.Read)
aImgGeneric = aImgFile(0)
aImgFile.Close()

aImg8 = CogImageConvert.GetIntensityImage(aImgGeneric, 0, 0, aImgGeneric.Width, aImgGeneric.Height)
Rect = New CogRectangle
Rect.SetXYWidthHeight(0, 0, aImg8.Width, aImg8.Height)
myBlobResults = myBlob.Execute(aImg8, Rect)