Color Match Edit ControlCognex VisionPro

The Color Match tool provides a graphical user interface to the CogColorMatchTool, which you use to examine an area of color in an image and generate a set of match scores between the examined area and a table of reference colors. The Color Match tool can be used to determine which color is currently present within an area of a run-time image. The following figure shows the Color Match tool edit control:

Cognex Color Match Color Match Color Match Whole Control

For more information on how a Color Match tool works, see the topic Color Matching.

The edit control allows you to perform the following actions:

  • Build a reference table of color values, using a color space of either Red, Green, Blue (RGB) or Hue, Saturation, Intensity (HSI).
  • Define the shape, size and location of the region the tool will use to examine the color contained in a run-time image.
  • Choose an algorithm the tool uses to generate the set of match scores, and assign different weight to the color planes of the defined color space.
  • Determine how the results the tool generates will be sorted.

If you add a CogColorMatchTool to a QuickBuild Job, it appears with an input terminal for the InputImage and output terminals for the best match score, the name of the color that generated the best match score, and the current confidence score, as shown in the following figure:

Cognex Color Match Color Match New Color Match In Job

See the topic Adding Edit Controls to Visual Studio for details on how to add a Color Match edit control to your Visual Studio.NET development environment if you are creating a vision application using the VisionPro application programming interface (API). The QuickBuild development environment supports the Color Match edit control automatically.

Control Buttons

Cognex Color Match Color Match Color Match Control Button Bar

The following table describes the function of each button:

Table 1. Control buttons
ButtonDescriptionFunction
Run Button
RunCalculate the average color value from the current region of interest and compare it against the table of reference colors, generating a score of how the color in the region compares against each known color.
Electric Button
Electric modeToggle electric mode, where the Color Match tool executes automatically when particular configuration parameters change. In electric mode, a lightning bolt appears next to every electric property.

Local Display Button

Local image display

Open or close the local image display window. A Color Match tool supports the following image buffers:

  • The Current.InputImage buffer contains the next image the tool will analyze plus a graphic for the current region of interest.
  • The LastRun.InputImage buffer contains the last image examined by the Color Match tool along with any graphics you enable from the Graphics tab.
Floating Display Button
Floating image displayOpen one or more floating image windows, which support the same image buffers as the local image display window.
Open Button
OpenOpen a VisionPro persistence (.vpp) file that contains a set of saved properties for this vision tool object type. VisionPro reports an error if you try to open a .vpp file for another object type.
Save Button
SaveSave the current properties of the Color Match tool to a VisionPro persistence (.vpp) file. The edit control allows you to choose between saving the Color Match tool with or without its image buffers and tool results.
Save As Button
Save AsSave the current properties of the vision tool to a new VisionPro persistence (.vpp) file.

Reset Button

Reset

Reset the vision tool to its default state.

The tool gives you a choice between resetting to the default-constructed state, which is appropriate when you are using it in a Visual Studio.NET application, or its template-initialized state, which is appropriate for QuickBuild applications.

Tool Tips Button
Show ToolTipsEnable or disable the display of tooltips for individual items in the edit control.
Help Button
HelpOpen this VisionPro online help file.
Colors Tab

Use the Colors tab to generate the table of reference colors the Color Match tool will compare against the region of interest in a run-time image. The following figure shows the Colors tab before any reference colors have been generated, as well as an image that can be used to generate them:

Cognex Color Match Color Match Color Match Colors Tab

Reference Table

The Colors tab displays a grid of the ColorCollection currently defined for the Color Match tool. Use the function buttons shown in the following figure to add, delete and reorder the items in the reference table:

Cognex Color Match Color Match Colors Tab Function Buttons

The following table describes what each button does:

Table 2. Reference Table Buttons
ButtonDescription

Cognex Color Match Color Match Add Point Function

Add a new reference color using either a specific point or by selecting a region of the Current.InputImage.

If you use a point to specify the new reference color, the Colors tab displays a point graphic over the Current.InputImage, as shown in the following figure:

Cognex Color Match Color Match Using Point Function

On the other hand, if you use a region to specify the new reference color, the Colors tab displays a region graphic over the Current.InputImage as well as the ability to control the properties of the region, as shown in the following figure:

Cognex Color Match Color Match Using Region Function

When you use a region, the Color Match tool computes an average from the color pixels the region contains.

In either case, select a point or region to add to your reference table and click Accept. The following figure shows a Colors tab with a list of reference colors:

Cognex Color Match Color Match Full Reference Colors Table

Cognex Color Match Color Match Delete Point Function
Remove the selected color from the reference table.
Cognex Color Match Color Match Move Up Function
IndexOf the selected color up one position in the reference table, although the order of the reference colors does not affect the operation of the Color Match tool.
Cognex Color Match Color Match Move Down Function
IndexOf the selected color down one position in the reference table, although the order of the reference colors does not affect the operation of the Color Match tool.
Currently Selected Color

The Colors tab includes an area for modifying the colors in the reference table:

Cognex Color Match Color Match Colors Tab Selected Color

You can modify a reference color at any time with the following controls:

Table 3. Currently Selected Color
ControlDescription
NameA name for the reference color that you can assign and change
ColorSpaceThe color space for the current reference color

Plane0

Plane1

Plane2

The values for the individual color planes in the defined color space.

Region Tab

Use the Region tab to specify the type of region you want to use to examine the run-time image. By default, the region of interest is configured to encompass the entire input image, but most applications will likely examine a portion of each acquired image. For example, the following figure shows the Region tab configured to use a rectangular region of interest:

Cognex Color Match Color Match Color Match Region Tab

Use the following controls to determine the region of interest:

Table 4. The Color Match Region Tab
FeatureDescription

Region

Select the shape of the input region. Selecting "None=Use entire image" means that the tool uses the entire input image. A Color Match tool supports the following input region shapes:

The set of region-defining parameters that appear depend on the region shape you use.

RegionMode

Defines how the tool interprets the region you specify.

  • Masked Region specifies that only the pixels that lie within the region are analyzed.
  • Bounding Box specifies that pixels that lie within a pixel-aligned bounding box that encloses the region are processed.
SelectedSpaceNameThe coordinate space in which the copy region is interpreted. For more information, see Coordinate Space Names.
Select ModeAvailable when Region Shape is CogRectangle or CogRectangleAffine. Selects the set of parameters that define the rectangle. If cogRectangleAffine is chosen, note that the angles of rotation and skew can be specified in degrees or radians, although the underlying tool keeps the measurements in radians.
FitToImageCenters the copy region within Current.InputImage.
RunParams Tab

Use the RunParams tab to choose a metric that controls how the Color Match weights the various color planes depending on the color space you are using. The following figure shows the RunParams tab:

Cognex Color Match Color Match Color Match Run Params Tab

Use the following controls to establish run parameters:

Table 5. The Color Match RunParams Tab
ControlDescription

MatchScoreMetricType

Select the correct scoring metric depending on the color space of your acquired images. The options are:

  • WeightedEuclideanDistanceInHSIColorSpace
  • WeightedEuclideanDistanceInRGBColorSpace
Distance WeightsSet a weight in the range of 0.0 to 1.0 for each of the Weight0, Weight1, Weight2 or Weight0, Weight0, Weight0 color planes in the color space of your acquired images. Increase the value of a particular plane can help the tool distinguish between colors that have a similar value in one particular plane.
SortResultSetByScoresBy default, the Color Match tool sorts results by the scores between the region of interest and the table of reference colors, but you can switch this to Index in order to have the tool display results according to the order of the colors in the reference table.
Graphics Tab

The Graphics tab allows you configure the diagnostic record and control whether the LastRun.InputImage shows the region of interest. The following figure shows the default Graphics tab:

Cognex Color Match Color Match Color Match Graphics Tab

For Show Input Image, determine whether or not the input image is recorded as part of the diagnostic record, and whether the image is copied to the record or saved in the record as a reference.

Check Show Region to enable a graphic on the LastRun.InputImage corresponding to the region on interest.

Results Tab

The Results tab displays the results from the last run of the tool. The following figure shows an example Results tab:

Cognex Color Match Color Match Color Match Results Tab

The edit control for the Color Match tool generates the following results:

Table 6. Color Match Results Tab
ResultDescription
ResultOfBestMatchThe Name and ResultOfBestMatch of the color that produced the best match between the region of interest in the reference table.
ConfidenceScoreAn indication of how much the best color match can be distinguished from other reference colors.
ColorThe three planar values, in either the RGB or HSI color space, of the observed color generated from the region in the run-time image.