Collapse
CollapsingX
  • - or -

Dealing with color images


Matrox Design Assistant supports color acquisition. Color processing is supported with the ColorMatcher step and with certain operations in the ImageProcessing step.

Color images contain 3 bands of data. Images grabbed in color mode from a color camera have red, green, and blue bands. Note that many of the Matrox Design Assistant steps only accept 1-band images.

Generally working with color

In some cases, it is more appropriate to convert the image to another format (for example, Hue (color information), Saturation (strength of the color), and Luminance) which is proportional to the intensity that would be captured with a monochrome camera. The ImageProcessing step has a Convert operation in the Copy and Convert category (along with Fill, Copy, and CopyConditional) that lets you convert an incoming RGB image into either a 3-band HSL image or into a 1-band image containing either hue, saturation, or luminance. On the first page of the Configuration pane of the ImageProcessing step you can specify if you want to produce a 1 or 3-band resulting image.

When a 3-band image is saved to a file, the color space type (RGB or HSL) is not saved in the file. By default, a 3-band image is considered to be RGB. If you have saved an HSL image and want to load it either through the Camera step, the LoadImage step, or through the static image repository, you must indicate that it is an HSL image using the Type property.

By default, when you add a step that only works with grayscale, the image will convert to grayscale using the image's luminance band. However, sometimes you might still receive a message indicating that the input image is not valid because the step only works on grayscale images. You will be prompted to select one band of your color input image, or to use an image processing step to convert the input image to grayscale. Perform one of the following options to clear this message.

  • If the camera used to grab images supports both color and monochrome, you can choose to set the camera color mode to grayscale in the Platform Configuration dialog. You will need to re-grab your images so they appear in grayscale.

  • If the project will not be using the color information, select the Convert to grayscale option in the Image sets page of the Platform Configuration dialog. By default, the Camera step will produce 1-band images (that is, grayscale images).

  • You can choose to work on one band individually, by linking the analysis step's Image property to one of the bands specified in the Alternate menu (sideways triangle). For an RGB image, selecting Red, Green, or Blue will extract that band from the original image, while selecting Hue will perform a conversion to produce a color-dependent hue image. Selecting Luminance will provide a grayscale equivalent of the original image. Note that if you have already used image processing to convert to an HSL, 3-band image, HS and L are available. Selecting Other gives access to the less commonly used Saturation (which requires that you are working with an image that has already been converted to HSL using an explicit ImageProcessing step). Other also offers the generic Band 1, Band 2, and Band 3 options.

  • Use the ImageProcessing step to produce a Luminance image (RGB to L) that you can use for operations such as locating or matching.

In Matrox Design Assistant, color components in a tree structure can also be referenced by color band with an index value, using the BandAtIndex notation. This is useful if the index depends on elements such as a variable or a loop counter.

  • Red: Camera.Image.Bands.BandAtIndex(1).

  • Green: Camera.Image.Bands.BandAtIndex(2).

  • Blue: Camera.Image.Bands.BandAtIndex(3).

Color matching

You can perform simple color determination (distinguishing between strong, uniform colors like red, green, blue, and yellow) in a number of ways:

  • Convert your image to HSL and use a single IntensityChecker step on the hue band. This approach requires extra care when dealing with black or white objects because their hue is not defined. Similarly, red objects can have hue values in 2 different ranges (for example, 0 to 10 and 245 to 255). A sample project is provided as an example. See Chapter 10: IntensityChecker step for more information.

  • Use multiple IntensityChecker steps on regions in each band, and compare 2 or 3 of the average values to expected ranges. For example, when distinguishing between red, green, and blue in a situation where there isn't enough time to convert to hue.

  • Use the difference between 2 color bands to distinguish colors. Red, green, and yellow (for example, in LEDs, traffic lights, and signal lights) can be reliably distinguished using the resulting signed image buffer derived from the red image minus the green image. Red will give positive numbers, green will give negative, and yellow (which is equal parts red and green) will give values close to zero. See the Arithmetic subsection of the ImageProcessing step operations section in Chapter 9: ImageProcessing step for more information.

  • Use white balancing to have a more accurate representation of the color temperature of an image. For more information, see Chapter 31: White balance.

Note that for reliable color matching, the camera should be white balanced. For information on white balancing, refer to Chapter 31: White balance.

If you require sophisticated color classification and matching, it might not be possible to distinguish between closely related colors with simple operations on the RGB and HSL images. To optimally convert a color image to grayscale, use the Projection operation from the ImageProcessing step. To perform color matching, use the ColorMatcher step.