Skip to content

Color Classifier vTool#

The Color Classifier vTool allows you to segment color images based on the color values of the pixels.

The Color Classifier vTool segments the input image into a region that contains only the pixels with the desired color based on a model that you teach during the setup of the vTool.

The Color Classifier vTool accepts an image via the Image input pin and outputs a single region via the Region output pin.

If you use the ROI Creator vTool to specify a region of interest before color classification, the Color Classifier accepts the ROI data via its Roi input pin. In that case, color classification is only performed on the region of interest. As a side effect, this results in faster processing.

The Region output of the Color Classifier vTool can also be used as Roi input for vTools with a Roi input pin. For more information, see the ROI Creator vTool topic.

Color Classifier vTool

How It Works#

The first step of color classification is the teaching of a model based on a representative image of the object to be classified by your application. In this teaching image, you mark the region of the desired color.

Info

When taking the teaching image, it is important that the illumination is identical to the illumination in your application environment. Particularly, the color or temperature of the illumination must not change.

Don't make the color definition region in the teaching image too small. Good classification results are achieved if all different shades of the color are included.

Once you've marked the color definition region, the Color Classifier has to be taught. Depending on the size of the input region the teaching may take a while to complete.

Lastly, specify the desired Sensitivity. The sensitivity is a measure of the likelihood that a pixel is recognized as having a matching color. A low sensitivity only recognizes pixels which are likely to be similar to the specified pixel colors. A high sensitivity will be more tolerant and recognize more pixels.

Info

Find the right Sensitivity value by adjusting this parameter and running tests on a representative set of images. The sensitivity setting doesn't affect the model taught.

There are applications where the color of the objects to be segmented varies but the color of the background remains the same. In this case, teach the background color and use the Invert pixel selection option to segment the foreground objects.

Info

It is very common that the color classification doesn't catch the complete target region or segments some additional, unwanted patches even if it has been taught correctly. Therefore, Basler recommends applying suitable region closing or opening operations with the Region Morphology vTool as a postprocessing step after the color classification.

Color Classification Example#

Assume that you want to find tomatoes in images containing tomatoes and oranges. The following image is used as a teaching image:

Color Classifier vTool Input Image

Now, mark some tomatoes using the pens and teach the model.

Color Classifier vTool Settings after Teaching

When applying this model to the input image, you get the following result where all four tomatoes are found:

Color Classifier vTool Result

Configuring the vTool#

To configure the Color Classifier vTool:

Color Classifier vTool Settings

  1. In the Recipe Management pane in the vTool Settings area, click Open Settings or double-click the vTool.
    The Color Classifier Basic dialog opens.
  2. Capture or open a teaching image.
    Either use the Single Shot button to grab a live image or click the Open Image button to open an existing image.
  3. Use the pens to mark the region of desired color in the image. To correct the region, you can use the eraser or delete it completely.
  4. Click the Teach button.
    This process may take a while.
  5. Adjust the Sensitivity parameter.
  6. Enable Invert pixel selection if you want to teach the background color instead of the object color.

You can view the result of the classification in a pin data view. Here, you can select which outputs to display.

Inputs#

Image#

Accepts images directly from a Camera vTool or from a vTool that outputs images, e.g., the Image Format Converter vTool.

  • Data type: Image
  • Image format: 8-bit to 16-bit color images

Roi#

Accepts a region of interest from the ROI Creator vTool or any other vTool that outputs regions or rectangles. Multiple rectangles or regions are merged internally to form a single region of interest.

  • Data type: RectangleF, RectangleF Array, Region, Region Array

Outputs#

Region#

Returns a single region that includes only the pixels that match the color value specified by you.

  • Data type: Region

Typical Predecessors#

Typical Successors#