Pixel Color Count¶
Class: PixelationCountBlockV1
Source: inference.core.workflows.core_steps.classical_cv.pixel_color_count.v1.PixelationCountBlockV1
Count pixels in an image that match a target color within a specified tolerance range, using color range masking to identify matching pixels and returning the total count of pixels within the color tolerance range for color analysis, quality control, color-based measurements, and pixel-level color quantification workflows.
How This Block Works¶
This block counts how many pixels in an image match a specific target color within a tolerance range, providing pixel-level color quantification. The block:
- Receives an input image and a target color specification (hex string, RGB tuple string, or RGB tuple)
- Converts the target color to BGR (Blue-Green-Red) format for OpenCV processing:
- Parses hex color strings (e.g., "#431112" or "#412" shorthand)
- Parses RGB tuple strings (e.g., "(128, 32, 64)")
- Handles RGB tuples directly (e.g., (18, 17, 67))
- Converts RGB to BGR format (reverses color channel order) since OpenCV uses BGR
- Calculates color tolerance bounds:
- Creates a lower bound by subtracting tolerance from each BGR channel of the target color
- Creates an upper bound by adding tolerance to each BGR channel of the target color
- Clips bounds to valid 0-255 range for each channel
- Defines a 3D color cube in BGR space where matching pixels must fall
- Creates a binary mask using OpenCV's inRange function:
- Compares each pixel's BGR values against the lower and upper bounds
- Sets mask pixel to 255 (white) if pixel color falls within the tolerance range
- Sets mask pixel to 0 (black) if pixel color falls outside the tolerance range
- Uses vectorized operations for efficient pixel-level comparison across the entire image
- Counts matching pixels:
- Counts non-zero pixels in the mask (pixels with value 255, representing matches)
- Returns the total count of pixels that match the target color within tolerance
The block performs pixel-level color matching using a tolerance-based approach, allowing for slight color variations due to compression, lighting, or image processing. The tolerance creates a range around the target color - a tolerance of 10 means pixels can differ by up to ±10 in each BGR channel (for a total range of 21 values per channel). Lower tolerance values (e.g., 5-10) require very close color matches, while higher tolerance values (e.g., 20-30) allow more color variation. This is useful for counting pixels of a specific color when exact matches may not exist due to image artifacts or processing.
Common Use Cases¶
- Color Area Measurement: Measure the area or coverage of specific colors in images (e.g., measure coverage of specific colors in images, quantify color distribution, assess color proportions), enabling color area quantification workflows
- Quality Control and Inspection: Count pixels of expected colors for quality control (e.g., verify color consistency in products, detect color defects, validate expected colors in images), enabling color-based quality control workflows
- Color-Based Analysis: Analyze images based on specific color presence or quantity (e.g., analyze color distribution in images, quantify color usage, measure color characteristics), enabling color quantification analysis workflows
- Image Processing Validation: Validate image processing results by counting expected colors (e.g., verify color transformations, validate color corrections, check color filtering results), enabling color validation workflows
- Feature Detection and Measurement: Detect and measure features based on color characteristics (e.g., count pixels in colored regions, measure color-based features, quantify color-defined areas), enabling color-based feature measurement workflows
- Threshold-Based Color Detection: Use pixel counting for threshold-based color detection (e.g., detect if enough pixels match a color, determine color presence thresholds, implement color-based triggers), enabling threshold-based color detection workflows
Connecting to Other Blocks¶
This block receives an image and target color, and produces a pixel count:
- After image input blocks to count pixels of specific colors in input images (e.g., count color pixels in camera feeds, analyze colors in image inputs, quantify colors in images), enabling color pixel counting workflows
- After crop blocks to count pixels in specific image regions (e.g., count color pixels in cropped regions, analyze colors in specific areas, quantify colors in selected regions), enabling region-based color pixel counting
- After preprocessing blocks to count pixels after image processing (e.g., count colors after filtering, analyze colors after enhancement, quantify colors after transformations), enabling processed image color counting workflows
- Before filtering or logic blocks that use pixel counts for decision-making (e.g., filter based on pixel counts, make decisions based on color quantities, apply logic based on pixel counts), enabling count-based conditional workflows
- Before data storage blocks to store pixel count information (e.g., store color pixel counts with images, save color analysis results, record color quantification data), enabling color count metadata storage workflows
- In quality control workflows where pixel counting validates color characteristics (e.g., verify color quantities in quality control, validate color coverage, check color consistency), enabling color-based quality control workflows
Type identifier¶
Use the following identifier in step "type" field: roboflow_core/pixel_color_count@v1to add the block as
as step in your workflow.
Properties¶
| Name | Type | Description | Refs |
|---|---|---|---|
name |
str |
Enter a unique identifier for this step.. | ❌ |
target_color |
Union[Tuple[int, int, int], str] |
Target color to count in the image. Can be specified in multiple formats: (1) Hex string format: '#RRGGBB' (6-digit, e.g., '#431112') or '#RGB' (3-digit shorthand, e.g., '#412'), (2) RGB tuple string format: '(R, G, B)' (e.g., '(128, 32, 64)'), or (3) RGB tuple: (R, G, B) tuple of integers (e.g., (18, 17, 67)). Values should be in RGB color space (0-255 per channel). The color is automatically converted to BGR format for OpenCV processing. Use this to specify the exact color you want to count pixels for.. | ✅ |
tolerance |
int |
Color matching tolerance value (0-255). Determines how much each BGR channel can vary from the target color and still be considered a match. The tolerance is applied to each color channel independently - a tolerance of 10 creates a range of ±10 for each BGR channel (total range of 21 values per channel). Lower values (e.g., 5-10) require very close color matches and are more precise but may miss slightly different shades. Higher values (e.g., 20-30) allow more color variation and match a wider range of similar colors but may include unintended colors. Default is 10, which provides a good balance. Adjust based on image quality, compression artifacts, and how strict you need the color matching to be.. | ✅ |
The Refs column marks possibility to parametrise the property with dynamic values available
in workflow runtime. See Bindings for more info.
Available Connections¶
Compatible Blocks
Check what blocks you can connect to Pixel Color Count in version v1.
- inputs:
Google Gemini,OpenAI,Trace Visualization,Twilio SMS Notification,Pixel Color Count,Image Preprocessing,Anthropic Claude,Image Slicer,VLM As Classifier,Dynamic Crop,LMM For Classification,Object Detection Model,Bounding Box Visualization,Webhook Sink,Halo Visualization,Mask Visualization,Template Matching,Absolute Static Crop,Pixelate Visualization,Twilio SMS/MMS Notification,MoonshotAI Kimi,SIFT Comparison,Dot Visualization,Multi-Label Classification Model,Image Stack,Stitch Images,Stitch OCR Detections,OpenAI,OPC UA Writer Sink,Google Gemini,Stability AI Inpainting,Email Notification,Distance Measurement,Frame Delay,EasyOCR,Keypoint Visualization,Llama 3.2 Vision,Florence-2 Model,LMM,Roboflow Custom Metadata,Auto Rotate on Edges,Image Slicer,Dominant Color,Keypoint Detection Model,OCR Model,Circle Visualization,Model Comparison Visualization,Stability AI Outpainting,Slack Notification,Line Counter Visualization,Camera Calibration,Contrast Enhancement,Relative Static Crop,Single-Label Classification Model,Clip Comparison,Morphological Transformation,Email Notification,Halo Visualization,VLM As Detector,Cosmos 3,CogVLM,Polygon Visualization,Camera Focus,Corner Visualization,Ellipse Visualization,Qwen-VL,Crop Visualization,PP-OCR,Google Gemma,Qwen 3.5 API,PLC Writer,Model Monitoring Inference Aggregator,Morphological Transformation,Anthropic Claude,Roboflow Visual Search,Icon Visualization,Heatmap Visualization,Color Visualization,Instance Segmentation Model,Google Gemma API,OpenAI,CSV Formatter,Image Blur,Triangle Visualization,Background Color Visualization,Grid Visualization,Detection Event Log,Image Contours,Image Threshold,Blur Visualization,GLM-OCR,Current Time,Roboflow Visual Search Classifier,QR Code Generator,Anthropic Claude,OpenAI-Compatible LLM,Florence-2 Model,Reference Path Visualization,Polygon Zone Visualization,Stitch OCR Detections,Roboflow Asset Library Attributes,Classification Label Visualization,Microsoft SQL Server Sink,Perspective Correction,Background Subtraction,Camera Focus,Image Convert Grayscale,Label Visualization,Contrast Equalization,Polygon Visualization,Google Vision OCR,SIFT,Stability AI Image Generation,Text Display,Llama 3.2 Vision,Qwen 3.6 API,Line Counter,MQTT Writer,MoonshotAI Kimi,Roboflow Dataset Upload,Local File Sink,OpenRouter,Qwen3.5-VL,Roboflow Vision Events,OpenAI,SIFT Comparison,Google Gemini,S3 Sink,Event Writer,Depth Estimation,Line Counter,Roboflow Dataset Upload - outputs:
Trace Visualization,Twilio SMS Notification,Pixel Color Count,Image Preprocessing,Anthropic Claude,Image Slicer,BoT-SORT Tracker,Object Detection Model,Bounding Box Visualization,Mask Edge Snap,Object Detection Model,Webhook Sink,Halo Visualization,Mask Visualization,Absolute Static Crop,Pixelate Visualization,Twilio SMS/MMS Notification,SIFT Comparison,Dot Visualization,Image Stack,Stitch Images,Stitch OCR Detections,Instance Segmentation Model,Email Notification,Stability AI Inpainting,Frame Delay,OPC UA Writer Sink,OC-SORT Tracker,Keypoint Visualization,Track Class Lock,Dynamic Zone,Auto Rotate on Edges,Image Slicer,Dominant Color,Byte Tracker,Keypoint Detection Model,PTZ Tracking (ONVIF),Stability AI Outpainting,Circle Visualization,Detections Classes Replacement,Slack Notification,Line Counter Visualization,Byte Tracker,SAM2 Video Tracker,ByteTrack Tracker,Morphological Transformation,Email Notification,Halo Visualization,Polygon Visualization,SORT Tracker,Ellipse Visualization,Corner Visualization,Crop Visualization,Morphological Transformation,Anthropic Claude,Keypoint Detection Model,Roboflow Visual Search,Heatmap Visualization,Icon Visualization,Color Visualization,Instance Segmentation Model,Motion Detection,Detections Consensus,Instance Segmentation Model,Triangle Visualization,Image Blur,Detections Stabilizer,Grid Visualization,Object Detection Model,Image Contours,Image Threshold,Blur Visualization,QR Code Generator,Roboflow Visual Search Classifier,Anthropic Claude,Reference Path Visualization,Stitch OCR Detections,Classification Label Visualization,Background Subtraction,Polygon Visualization,Perspective Correction,Label Visualization,Detection Offset,Text Display,Instance Segmentation Model,MQTT Writer,Identify Outliers,Roboflow Vision Events,Identify Changes,Keypoint Detection Model,SIFT Comparison,Event Writer,Byte Tracker
Input and Output Bindings¶
The available connections depend on its binding kinds. Check what binding kinds
Pixel Color Count in version v1 has.
Bindings
-
input
image(image): Input image to analyze for pixel color counting. The block counts pixels in this image that match the target_color within the specified tolerance. All pixels in the image are analyzed. The image is processed in BGR format (OpenCV standard), and color matching is performed on each pixel's BGR values. Processing time depends on image size..target_color(Union[string,rgb_color]): Target color to count in the image. Can be specified in multiple formats: (1) Hex string format: '#RRGGBB' (6-digit, e.g., '#431112') or '#RGB' (3-digit shorthand, e.g., '#412'), (2) RGB tuple string format: '(R, G, B)' (e.g., '(128, 32, 64)'), or (3) RGB tuple: (R, G, B) tuple of integers (e.g., (18, 17, 67)). Values should be in RGB color space (0-255 per channel). The color is automatically converted to BGR format for OpenCV processing. Use this to specify the exact color you want to count pixels for..tolerance(integer): Color matching tolerance value (0-255). Determines how much each BGR channel can vary from the target color and still be considered a match. The tolerance is applied to each color channel independently - a tolerance of 10 creates a range of ±10 for each BGR channel (total range of 21 values per channel). Lower values (e.g., 5-10) require very close color matches and are more precise but may miss slightly different shades. Higher values (e.g., 20-30) allow more color variation and match a wider range of similar colors but may include unintended colors. Default is 10, which provides a good balance. Adjust based on image quality, compression artifacts, and how strict you need the color matching to be..
-
output
matching_pixels_count(integer): Integer value.
Example JSON definition of step Pixel Color Count in version v1
{
"name": "<your_step_name_here>",
"type": "roboflow_core/pixel_color_count@v1",
"image": "$inputs.image",
"target_color": "#431112",
"tolerance": 10
}