# Extract Colors

This guide explains how to match pixels only to the Pantone 274-2 color using the TrainExtractColor and ExtractColor functions.

The guide uses the following input image:

## Using the TrainExtractColor Function

1. Add the TrainExtractColor function Functions are tools that are available in Spreadsheet for processing and analyzing acquisitions or other results. You can add functions to your Spreadsheet job to create tool chains and produce results for specific applications. to your job A job is a user-configured program in In-Sight Spreadsheet consisting of functions and designed for specific applications. You can create and edit jobs using the In-Sight Spreadsheet interface, and load them on a vision system for deployment in a live environment..

2. In the property sheet, create a color model named Pantone 247-2.

3. Add a new color to the color model.

4. Place the sample ROI over the 274-2 green color in the input image.

   Note: The purple overlay in the image indicates that too many pixels match. The reason for this is that the lighting is not uniform and the default tolerances allow too many matching pixels.

5. Adjust the color tolerances. With tightened tolerances, the results are better but the result still matches pixels with the 274-1 and 274-3 colors.

6. Subtract the 274-1 and 274-3 colors and adjust the color tolerances for them to improve the results.

The order of the colors in the model is important. Compare the two examples below:

Action | Effect | Resulting Pixel Count
Add Pantone 274-2 | Adds greenish pixels to the result. | 1000
Subtract Pantone 274-3 | Removes lighter green pixels from the result that were previously added. | 750
Subtract Pantone 274-1 | Removes darker green pixels from the result that were previously added. | 500

Result: 500 matching pixels

Action | Effect | Resulting Pixel Count
Subtract Pantone 274-3 | Removes lighter green pixels from the result that were previously added. | 0
Subtract Pantone 274-1 | Removes darker green pixels from the result that were previously added. | 0
Add Pantone 274-2 | Adds greenish pixels to the result. | 1000

Result: 1000 matching pixels

## Using the ExtractColor Function

This guide explains how to match pixels only to the Pantone 274-2 color using the ExtractColor function by referencing the color trained in the previous guide with the TrainExtractColor function.

1. Add an ExtractColor function to your job that references the ExtractColorLib data structure output by the previous procedure.

2. On the Color Models tab of the property sheet, only enable the Pantone 274-2 color model.

   Note: The purpose of this guide is only verifying the Pantone 274-2 color with the ExtractColor function. If you added more colors or color models to the library, those models and colors are not important for the current ExtractColor function and they can interfere with the results.

3. Check the Count Pixels option in the property sheet to generate a pixel count. When enabled, pixel count results are available for the GetOverallPixelCount, GetPixelCountByIndex, GetPixelCountByName functions.

4. Set the Output Image parameter to the Binary Image option.

After you finish, you can pass this output image on to a Filter or DetectBlob function, for example, for additional processing.