Image Threshold¶
Class: ImageThresholdBlockV1
Source: inference.core.workflows.core_steps.classical_cv.threshold.v1.ImageThresholdBlockV1
Convert grayscale images to binary images using configurable thresholding methods (binary, binary_inv, trunc, tozero, tozero_inv, adaptive_mean, adaptive_gaussian, otsu) to separate foreground from background, isolate objects, prepare images for morphological operations, and create binary masks for segmentation, object detection, and analysis workflows.
How This Block Works¶
This block applies thresholding operations to convert grayscale images into binary images where pixels are classified as either foreground (white) or background (black). The block:
- Receives a grayscale input image (color images must be converted to grayscale first using an Image Convert Grayscale block)
- Determines the thresholding method from the threshold_type parameter
- Applies the selected thresholding operation:
For Binary Threshold: - Uses a fixed threshold value (thresh_value) - Pixels above the threshold become max_value (white), pixels below become 0 (black) - Creates a binary image with clear separation between foreground and background - Best for images with uniform lighting and clear contrast
For Binary Inverse Threshold: - Uses a fixed threshold value (thresh_value) - Pixels above the threshold become 0 (black), pixels below become max_value (white) - Inverts the binary result - dark objects become white, light backgrounds become black - Useful when dark objects need to be foreground (white) in the output
For Truncate Threshold: - Uses a fixed threshold value (thresh_value) - Pixels above the threshold are set to the threshold value, pixels below remain unchanged - Clips bright pixels while preserving dark pixel values - Useful for reducing brightness in overexposed regions
For To Zero Threshold: - Uses a fixed threshold value (thresh_value) - Pixels below the threshold are set to 0 (black), pixels above remain unchanged - Removes dark pixels while preserving bright pixel values - Useful for removing noise in dark regions
For To Zero Inverse Threshold: - Uses a fixed threshold value (thresh_value) - Pixels above the threshold are set to 0 (black), pixels below remain unchanged - Removes bright pixels while preserving dark pixel values - Useful for removing noise in bright regions
For Adaptive Mean Threshold: - Calculates threshold values locally using mean of neighborhood pixels - Adapts to local image characteristics (block size 11x11, constant 2) - Handles varying lighting conditions and illumination gradients - Best for images with non-uniform lighting
For Adaptive Gaussian Threshold: - Calculates threshold values locally using weighted Gaussian mean of neighborhood pixels - Adapts to local image characteristics (block size 11x11, constant 2) - Handles varying lighting conditions with smoother transitions than adaptive mean - Best for images with non-uniform lighting requiring smoother adaptation
For Otsu's Threshold: - Automatically calculates optimal threshold value using Otsu's method - Analyzes histogram to find threshold that minimizes intra-class variance - No manual threshold value needed (thresh_value is ignored) - Best for bimodal histograms with clear foreground/background separation
- For fixed threshold methods (binary, binary_inv, trunc, tozero, tozero_inv), uses thresh_value as the threshold and max_value (typically 255) as the maximum output value
- For adaptive methods (adaptive_mean, adaptive_gaussian), uses max_value as the maximum output value and adapts locally
- For Otsu's method, automatically determines the optimal threshold and uses max_value as the maximum output value
- Preserves image structure and metadata
- Returns the thresholded binary image
Thresholding converts grayscale images to binary images by classifying pixels based on intensity values. Fixed threshold methods use a single threshold value for the entire image - simple and fast but sensitive to lighting variations. Adaptive threshold methods calculate local thresholds for each pixel neighborhood - more robust to lighting variations but computationally more expensive. Otsu's method automatically selects an optimal global threshold by analyzing the image histogram - works well for images with bimodal intensity distributions. The threshold_type controls the method, thresh_value sets the threshold for fixed methods, and max_value (typically 255) determines the white pixel value in binary outputs.
Common Use Cases¶
- Binary Image Creation: Convert grayscale images to binary images for object detection and analysis (e.g., create binary masks, isolate objects from background, separate foreground and background), enabling binary image creation workflows
- Object Segmentation: Isolate objects from backgrounds for segmentation tasks (e.g., segment objects from backgrounds, create object masks, isolate regions of interest), enabling object segmentation workflows
- Document Processing: Extract text and content from scanned documents (e.g., binarize document images, enhance text contrast, prepare documents for OCR), enabling document processing workflows
- Image Preprocessing: Prepare images for morphological operations and contour detection (e.g., create binary images for morphology, prepare images for contour analysis, binarize for shape analysis), enabling preprocessing workflows
- Noise Removal Preparation: Create binary images for noise removal and cleaning operations (e.g., prepare images for morphological cleaning, create masks for filtering, binarize for denoising), enabling noise removal workflows
- Feature Detection: Prepare images for feature detection and analysis (e.g., create binary images for edge detection, prepare for feature extraction, binarize for pattern recognition), enabling feature detection workflows
Connecting to Other Blocks¶
This block receives a grayscale image and produces a thresholded binary image:
- After Image Convert Grayscale blocks to convert color images to grayscale before thresholding (e.g., convert color to grayscale then threshold, prepare color images for binarization, grayscale before binary conversion), enabling color-to-binary workflows
- After preprocessing blocks that output grayscale images (e.g., apply thresholding after filtering, binarize after enhancement, threshold preprocessed images), enabling preprocessing-to-threshold workflows
- Before morphological transformation blocks to prepare binary images for morphological operations (e.g., clean thresholded images with morphology, apply morphology to binary images, process binary masks), enabling threshold-to-morphology workflows
- Before contour detection blocks to prepare binary images for contour detection (e.g., find contours in thresholded images, detect shapes in binary images, analyze binary object boundaries), enabling threshold-to-contour workflows
- Before analysis blocks that process binary images (e.g., analyze binary masks, process thresholded regions, work with binary object data), enabling threshold analysis workflows
- In image processing pipelines where thresholding is part of a larger binary image processing chain (e.g., binarize images in pipelines, create masks in workflows, process binary images in chains), enabling threshold processing pipeline workflows
Requirements¶
This block requires grayscale input images. Color images must be converted to grayscale first using an Image Convert Grayscale block. For optimal results, use images with good contrast between foreground and background. Fixed threshold methods work best with uniform lighting, while adaptive methods handle non-uniform lighting better. Otsu's method works best with bimodal histograms (clear foreground/background separation).
Type identifier¶
Use the following identifier in step "type" field: roboflow_core/threshold@v1to add the block as
as step in your workflow.
Properties¶
| Name | Type | Description | Refs |
|---|---|---|---|
name |
str |
Enter a unique identifier for this step.. | ❌ |
threshold_type |
str |
Type of thresholding operation to apply: 'binary' (default, pixels above threshold become white, below become black) for uniform lighting, 'binary_inv' (inverse binary, pixels above threshold become black, below become white) for dark object isolation, 'trunc' (truncate, pixels above threshold set to threshold value) for brightness clipping, 'tozero' (to zero, pixels below threshold set to zero) for dark region removal, 'tozero_inv' (to zero inverse, pixels above threshold set to zero) for bright region removal, 'adaptive_mean' (adaptive mean, local threshold using mean of neighborhood) for non-uniform lighting, 'adaptive_gaussian' (adaptive Gaussian, local threshold using weighted Gaussian mean) for non-uniform lighting with smoother transitions, or 'otsu' (Otsu's method, automatic optimal threshold calculation) for bimodal histograms. Default is 'binary'. Fixed methods (binary, binary_inv, trunc, tozero, tozero_inv) use thresh_value, adaptive methods (adaptive_mean, adaptive_gaussian) adapt locally, and Otsu's method automatically calculates the optimal threshold.. | ✅ |
thresh_value |
int |
Threshold value used for fixed threshold methods (binary, binary_inv, trunc, tozero, tozero_inv). Must be an integer between 0 and 255. Pixels above this value are treated as foreground for binary/binary_inv, or clipped/preserved for trunc/tozero/tozero_inv depending on the operation. Typical values range from 100-200: lower values (100-127) for darker images or to preserve more dark regions, medium values (127-150) for balanced separation, higher values (150-200) for brighter images or to preserve more bright regions. Default is 127 (middle gray). This parameter is ignored for adaptive methods (adaptive_mean, adaptive_gaussian) and Otsu's method (otsu) which calculate thresholds automatically. Adjust based on image brightness and desired foreground/background separation.. | ✅ |
max_value |
int |
Maximum value used in thresholded binary outputs. Must be an integer, typically 255 (white pixel value in 8-bit images). This value is assigned to pixels classified as foreground in binary operations (binary, binary_inv) or used as the maximum value in adaptive thresholding (adaptive_mean, adaptive_gaussian, otsu). For truncate operations (trunc), this parameter is used but the actual output values are clipped to thresh_value. Default is 255, which creates standard binary images with white (255) foreground and black (0) background. For 8-bit grayscale images, keep at 255. For 16-bit images, use 65535. Controls the brightness/intensity of foreground pixels in the thresholded output.. | ✅ |
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 Image Threshold in version v1.
- inputs:
Image Slicer,Polygon Zone Visualization,VLM As Classifier,Line Counter,Contrast Enhancement,Google Gemma API,MoonshotAI Kimi,Stability AI Image Generation,Image Threshold,Line Counter Visualization,Trace Visualization,Stitch OCR Detections,Distance Measurement,Image Stack,Camera Calibration,QR Code Generator,Anthropic Claude,Detection Event Log,Icon Visualization,SIFT Comparison,Morphological Transformation,S3 Sink,Color Visualization,LMM For Classification,Perspective Correction,Microsoft SQL Server Sink,Corner Visualization,Roboflow Custom Metadata,Google Vision OCR,Twilio SMS Notification,Halo Visualization,Image Blur,Morphological Transformation,Qwen-VL,Camera Focus,Email Notification,Roboflow Vision Events,Halo Visualization,Stability AI Inpainting,Classification Label Visualization,Stitch OCR Detections,Google Gemma,Event Writer,Grid Visualization,Qwen3.5-VL,Background Color Visualization,Mask Visualization,Llama 3.2 Vision,Ellipse Visualization,Email Notification,Reference Path Visualization,Image Slicer,Label Visualization,Twilio SMS/MMS Notification,Text Display,SIFT Comparison,OPC UA Writer Sink,Dot Visualization,Polygon Visualization,Crop Visualization,Dynamic Crop,Absolute Static Crop,Circle Visualization,Image Preprocessing,Llama 3.2 Vision,Model Monitoring Inference Aggregator,Relative Static Crop,Camera Focus,OpenRouter,OpenAI,Template Matching,Florence-2 Model,OpenAI-Compatible LLM,MoonshotAI Kimi,Heatmap Visualization,Single-Label Classification Model,OpenAI,OCR Model,CogVLM,Blur Visualization,Depth Estimation,Instance Segmentation Model,Stability AI Outpainting,Anthropic Claude,Google Gemini,Qwen 3.6 API,Clip Comparison,Google Gemini,Background Subtraction,Keypoint Visualization,CSV Formatter,Webhook Sink,Bounding Box Visualization,Multi-Label Classification Model,LMM,OpenAI,Stitch Images,Florence-2 Model,Image Convert Grayscale,Current Time,Contrast Equalization,OpenAI,VLM As Detector,Line Counter,Google Gemini,Roboflow Visual Search,Triangle Visualization,Slack Notification,EasyOCR,Roboflow Dataset Upload,Pixelate Visualization,Roboflow Dataset Upload,PLC Writer,SIFT,Qwen 3.5 API,Anthropic Claude,Object Detection Model,Local File Sink,MQTT Writer,Image Contours,Polygon Visualization,Keypoint Detection Model,Pixel Color Count,GLM-OCR,Model Comparison Visualization,Roboflow Asset Library Attributes - outputs:
VLM As Classifier,MoonshotAI Kimi,Stability AI Image Generation,Trace Visualization,Qwen2.5-VL,Image Stack,Anthropic Claude,Icon Visualization,SIFT Comparison,Morphological Transformation,Color Visualization,SmolVLM2,LMM For Classification,Single-Label Classification Model,Perspective Correction,Corner Visualization,Clip Comparison,Halo Visualization,Qwen-VL,Keypoint Detection Model,Halo Visualization,Object Detection Model,Google Gemma,Background Color Visualization,Ellipse Visualization,Email Notification,Twilio SMS/MMS Notification,Text Display,Polygon Visualization,Crop Visualization,Absolute Static Crop,Image Preprocessing,Template Matching,Relative Static Crop,OpenRouter,OpenAI,Florence-2 Model,VLM As Detector,OpenAI,Motion Detection,Heatmap Visualization,OCR Model,Perception Encoder Embedding Model,Blur Visualization,Barcode Detection,Depth Estimation,Instance Segmentation Model,Stability AI Outpainting,Anthropic Claude,YOLO-World Model,Google Gemini,Clip Comparison,Google Gemini,Background Subtraction,Keypoint Visualization,Buffer,Stitch Images,Florence-2 Model,Contrast Equalization,Mask Edge Snap,OpenAI,Qwen3-VL,Moondream2,VLM As Detector,Google Gemini,Triangle Visualization,CLIP Embedding Model,Detections Stabilizer,SIFT,Multi-Label Classification Model,Image Contours,Keypoint Detection Model,VLM As Classifier,Pixel Color Count,GLM-OCR,Image Slicer,Polygon Zone Visualization,Contrast Enhancement,Google Gemma API,Time in Zone,Semantic Segmentation Model,Image Threshold,Line Counter Visualization,Semantic Segmentation Model,Multi-Label Classification Model,Camera Calibration,ByteTrack Tracker,Google Vision OCR,Image Blur,Morphological Transformation,Camera Focus,Roboflow Vision Events,Stability AI Inpainting,Classification Label Visualization,SAM2 Video Tracker,Event Writer,Qwen3.5-VL,Mask Visualization,Llama 3.2 Vision,Dominant Color,Reference Path Visualization,Image Slicer,Label Visualization,Byte Tracker,Dot Visualization,Dynamic Crop,Detections Stitch,Circle Visualization,Llama 3.2 Vision,BoT-SORT Tracker,SAM3 Video Tracker,Camera Focus,Gaze Detection,Segment Anything 2 Model,MoonshotAI Kimi,Single-Label Classification Model,QR Code Detection,Qwen3.5,CogVLM,Object Detection Model,SAM 3 Interactive,Qwen 3.6 API,Bounding Box Visualization,Multi-Label Classification Model,LMM,OpenAI,SAM 3,Image Convert Grayscale,Instance Segmentation Model,EasyOCR,Roboflow Visual Search,Roboflow Dataset Upload,SAM 3,Instance Segmentation Model,Keypoint Detection Model,Pixelate Visualization,Roboflow Dataset Upload,SORT Tracker,Instance Segmentation Model,Track Class Lock,Qwen 3.5 API,Object Detection Model,Anthropic Claude,Polygon Visualization,OC-SORT Tracker,SAM 3,Model Comparison Visualization,Single-Label Classification Model,Seg Preview
Input and Output Bindings¶
The available connections depend on its binding kinds. Check what binding kinds
Image Threshold in version v1 has.
Bindings
-
input
image(image): Input grayscale image to apply thresholding to. Must be a single-channel grayscale image (color images must be converted to grayscale first using an Image Convert Grayscale block). Thresholding converts grayscale images to binary images where pixels are classified as foreground (white) or background (black). The thresholded binary image will have pixels set to either 0 (black) or max_value (typically 255, white) based on the selected thresholding method. Original image metadata is preserved in the output. For optimal results, use images with good contrast between foreground and background..threshold_type(string): Type of thresholding operation to apply: 'binary' (default, pixels above threshold become white, below become black) for uniform lighting, 'binary_inv' (inverse binary, pixels above threshold become black, below become white) for dark object isolation, 'trunc' (truncate, pixels above threshold set to threshold value) for brightness clipping, 'tozero' (to zero, pixels below threshold set to zero) for dark region removal, 'tozero_inv' (to zero inverse, pixels above threshold set to zero) for bright region removal, 'adaptive_mean' (adaptive mean, local threshold using mean of neighborhood) for non-uniform lighting, 'adaptive_gaussian' (adaptive Gaussian, local threshold using weighted Gaussian mean) for non-uniform lighting with smoother transitions, or 'otsu' (Otsu's method, automatic optimal threshold calculation) for bimodal histograms. Default is 'binary'. Fixed methods (binary, binary_inv, trunc, tozero, tozero_inv) use thresh_value, adaptive methods (adaptive_mean, adaptive_gaussian) adapt locally, and Otsu's method automatically calculates the optimal threshold..thresh_value(integer): Threshold value used for fixed threshold methods (binary, binary_inv, trunc, tozero, tozero_inv). Must be an integer between 0 and 255. Pixels above this value are treated as foreground for binary/binary_inv, or clipped/preserved for trunc/tozero/tozero_inv depending on the operation. Typical values range from 100-200: lower values (100-127) for darker images or to preserve more dark regions, medium values (127-150) for balanced separation, higher values (150-200) for brighter images or to preserve more bright regions. Default is 127 (middle gray). This parameter is ignored for adaptive methods (adaptive_mean, adaptive_gaussian) and Otsu's method (otsu) which calculate thresholds automatically. Adjust based on image brightness and desired foreground/background separation..max_value(integer): Maximum value used in thresholded binary outputs. Must be an integer, typically 255 (white pixel value in 8-bit images). This value is assigned to pixels classified as foreground in binary operations (binary, binary_inv) or used as the maximum value in adaptive thresholding (adaptive_mean, adaptive_gaussian, otsu). For truncate operations (trunc), this parameter is used but the actual output values are clipped to thresh_value. Default is 255, which creates standard binary images with white (255) foreground and black (0) background. For 8-bit grayscale images, keep at 255. For 16-bit images, use 65535. Controls the brightness/intensity of foreground pixels in the thresholded output..
-
output
image(image): Image in workflows.
Example JSON definition of step Image Threshold in version v1
{
"name": "<your_step_name_here>",
"type": "roboflow_core/threshold@v1",
"image": "$inputs.image",
"threshold_type": "binary",
"thresh_value": 127,
"max_value": 255
}