Measure Color Statistics

NI Vision for LabVIEW Basics

Measure Color Statistics

Most image processing and analysis functions apply to 8-bit and 16-bit images. However, you can analyze and process individual components of a color image.

Using the IMAQ ExtractColorPlanes VI, you can break down a color image into various sets of primary components, such as RGB (Red, Green, and Blue), HSI (Hue, Saturation, and Intensity), HSL (Hue, Saturation, and Luminance), or HSV (Hue, Saturation, and Value). Each component becomes an 8-bit or 16-bit image that you can process like any other grayscale image. Using the IMAQ ReplaceColorPlane VI, you can reassemble a color image from a set of three 8-bit or 16-bit images, where each image becomes one of the three primary components. The following figures illustrate how 32-bit and 64-bit color images break down into their three primary components.

Use the IMAQ ExtractSingleColorPlane VI or the IMAQ ExtractColorPlanes VI to extract the red, green, blue, hue saturation, intensity, luminance, or value plane of a color image into an 8-bit image.

A color pixel encoded as an unsigned 32-bit integer control can be decomposed into its individual components using the IMAQ IntegerToColorValue VI. You can convert a pixel value represented by its RGB components into the equivalent components for another color model using the IMAQ RGBToColor 2 VI. You can convert components in any other color mode to RGB by using the IMAQ ColorToRGB VI.

Comparing Colors

You can use the color matching capability of NI Vision to compare or evaluate the color content of an image or regions in an image. Complete the following steps to compare colors using color matching:

  1. Select an image containing the color information that you want to use as a reference. The color information can consist of multiple colors.
  2. Use the entire image or regions in the image to learn the color information using the IMAQ ColorLearn VI, which outputs a color spectrum that contains a compact description of the color information that you learned. Refer to Chapter 15, Color Inspection, of the NI Vision Concepts Manual for more information. Use the color spectrum to represent the learned color information for all subsequent matching operations.
  3. Define an image or multiple regions in an image as the inspection or comparison area.
  4. Use the IMAQ ColorMatch VI to compare the learned color information to the color information in the inspection regions. This VI returns a score that indicates the closeness of match. You can specify a Minimum Match Score, which indicates if there is a match between the input color information and the color in each specified region in the image.
  5. Use the color matching score as a measure of similarity between the reference color information and the color information in the image regions being compared.

Learning Color Information

When learning color information, choose the color information carefully by specifying an image or regions in an image that contain the color or color set that you want to learn, selecting how detailed you want the color information to be learned, and choosing colors that you want to ignore during matching.

Specifying the Color Information to Learn

Because color matching uses only color information to measure similarity, the image or regions in the image representing the object should contain only the significant colors that represent the object, as shown in Figure A. Figure B illustrates an unacceptable region containing background colors.

The following sections explain when to learn the color information associated with an entire image, a region in an image, or multiple regions in an image.

Using the Entire Image

You can use an entire image to learn the color spectrum that represents the entire color distribution of the image. In a fabric identification application, for example, an entire image can specify the color information associated with a certain fabric type, as shown in the following figure.

Using a Region in the Image

You can select a region in the image to provide the color information for comparison. A region is helpful for pulling out the useful color information in an image. The following figure shows an example of using a region that contains the color information that is important for the application.

Using Multiple Regions in the Image

The interaction of light with an object surface creates the observed color of that object. The color of a surface depends on the directions of illumination and the direction from which the surface is observed. Two identical objects may have different appearances because of a difference in positioning or a change in the lighting conditions.

The following figure shows how light reflects differently off of the 3D surfaces of the fuses, resulting in slightly different colors for identical fuses. Compare the 3-amp fuse in the upper row with the 3-amp fuse in the lower row. The difference in light reflection results in different color spectrums for identical fuses.

If you learn the color spectrum by drawing a region of interest inside the 3-amp fuse in the upper row and then do a color matching for the 3-amp fuse in the upper row, you get a very high match score close to 1000. However, the match score for the 3-amp fuse in the lower row is quite low at around 500. This problem could cause a mismatch for the color matching in a fuse box inspection process.

The color learning algorithm of NI Vision uses a clustering process to find the representative colors from the color information specified by one or multiple regions in the image. To create a representative color spectrum for all 3-amp fuses in the learning phase, draw an ROI around the three amp fuse in the upper row, hold down the <Ctrl> key, and draw another ROI around the 3-amp fuse in the lower row. The new color spectrum represents 3-amp fuses much better and results in high match scores—near 800—for both 3-amp fuses. Use as many samples as you want in an image to learn the representative color spectrum for a specified template.

1   Regions Used to Learn Color Information  

Choosing a Color Representation Sensitivity

When you learn a color, you need to specify the sensitivity required to specify the color information. An image containing a few, well-separated colors in the color space requires a lower sensitivity to describe the color than an image that contains colors that are close to one another in the color space. Use the Color Sensitivity control of the IMAQ ColorLearn VI to specify the granularity you want to use to represent the colors.

Ignoring Learned Colors

Ignore certain color components in color matching by replacing the corresponding component in the input color spectrum array to –1. For example, by replacing the last component in the color spectrum with –1, the white color is ignored during the color matching process. By replacing the second to last component in the color spectrum, the black color is ignored during the color matching process.

To ignore other color components in color matching, determine the index to the color spectrum by locating the corresponding bins in the color wheel, where each bin corresponds to a component in the color spectrum array. Ignoring certain colors, such as the background color, results in a more accurate color matching score. Ignoring the background color also provides more flexibility when defining the regions of interest in the color matching process. Ignoring certain colors, such as the white color created by glare on a metallic surface, also improves the accuracy of the color matching. Experiment learning the color information about different parts of the images to determine which colors to ignore. Refer to Chapter 15, Color Inspection, of the NI Vision Concepts Manual for more information about the color wheel and color bins.