Dynamic Crop¶
Class: DynamicCropBlockV1
Source: inference.core.workflows.core_steps.transformations.dynamic_crop.v1.DynamicCropBlockV1
Extract cropped image regions from input images based on bounding boxes from detection model predictions, supporting object detection, instance segmentation, and keypoint detection models with optional background removal using segmentation masks for focused region extraction and multi-stage analysis workflows.
How This Block Works¶
This block crops rectangular regions from input images using bounding boxes from detection model outputs, producing individual cropped images for each detected object. The block:
- Receives input images and detection predictions (object detection, instance segmentation, or keypoint detection) containing bounding boxes
- Validates that predictions contain detection IDs required for crop tracking
- Extracts each bounding box from the predictions and crops the corresponding rectangular region from the input image
- For instance segmentation predictions with
mask_opacity > 0: Applies background removal by overlaying the segmentation mask, replacing background pixels outside the detected instance with the specifiedbackground_colorand blending with the original crop based on mask opacity - Creates cropped image objects with metadata tracking the crop's origin (original image, offset coordinates, detection ID)
- Translates prediction coordinates from the original image space to the cropped region space (adjusts bounding boxes, masks, keypoints, and polygons to be relative to the crop origin)
- Returns a list of results for each detection, each containing the cropped image and the translated predictions
The block processes each detection's bounding box independently, creating separate crops for each detected object. For instance segmentation predictions, the optional background removal feature uses the segmentation mask to isolate the detected object from background pixels, useful for creating clean object-focused crops. All prediction coordinates (bounding boxes, keypoints, polygons, mask coordinates) are automatically translated to be relative to the cropped region's top-left corner, ensuring downstream blocks can process the crops correctly. The block increases output dimensionality by one (produces a list of crops per input image), enabling batch processing workflows where each crop can be processed independently.
Common Use Cases¶
- Multi-Stage Object Analysis: Extract individual object crops from full images for detailed analysis (e.g., detect objects in a scene, crop each detected object, then run OCR or classification on individual crops), enabling focused analysis of specific regions without processing entire images
- Background Removal for Object Focus: Create clean object crops with background removed using segmentation masks (e.g., detect and segment objects, crop with background removal, create isolated object images for training or analysis), enabling focused object extraction and cleaner downstream processing
- Region-Based Processing Pipelines: Extract regions of interest for specialized processing (e.g., detect text regions, crop each text region, run OCR on crops; detect faces, crop each face, run face recognition), enabling efficient processing of specific image regions
- Keypoint and Annotation Preservation: Extract object crops while preserving detection annotations (e.g., detect objects with keypoints, crop objects maintaining keypoint coordinates, analyze keypoints in cropped context), enabling focused analysis with full annotation context
- Batch Region Extraction: Extract multiple regions from single images for parallel processing (e.g., detect all objects in image, crop each object separately, process crops in parallel for classification or analysis), enabling efficient batch processing of multiple regions
- Training Data Preparation: Create cropped object datasets from annotated images (e.g., detect objects with bounding boxes, crop each object individually, export crops for training data collection), enabling automated extraction of training samples from full images
Connecting to Other Blocks¶
This block receives images and detection predictions, producing cropped images:
- After detection blocks (e.g., Object Detection, Instance Segmentation, Keypoint Detection) to extract individual object regions based on detected bounding boxes, enabling focused analysis of detected objects in isolation
- Before classification or analysis blocks that need object-focused inputs (e.g., OCR for text regions, fine-grained classification for cropped objects, detailed feature extraction), enabling specialized processing of individual regions rather than full images
- In multi-stage detection workflows where initial detections are used to extract regions for secondary analysis (e.g., detect vehicles, crop each vehicle, detect license plates in crops), enabling hierarchical detection and analysis pipelines
- Before visualization blocks that display individual objects (e.g., display cropped objects separately, create galleries of detected objects, show isolated object annotations), enabling focused visualization of extracted regions
- After detection blocks with instance segmentation to create clean object crops with background removal, enabling isolated object images for analysis, training, or presentation
- In keypoint detection workflows where keypoint coordinates need to be preserved in cropped contexts (e.g., detect people with keypoints, crop each person, analyze pose in cropped images), enabling keypoint analysis in focused image regions
Type identifier¶
Use the following identifier in step "type" field: roboflow_core/dynamic_crop@v1to add the block as
as step in your workflow.
Properties¶
| Name | Type | Description | Refs |
|---|---|---|---|
name |
str |
Enter a unique identifier for this step.. | โ |
mask_opacity |
float |
Background removal opacity for instance segmentation crops (0.0 to 1.0). Only applies when predictions contain segmentation masks (instance segmentation predictions). Controls how aggressively background pixels outside the detected instance are removed: 0.0 leaves the crop unchanged (no background removal), 1.0 fully replaces background with background_color, values between blend the original crop with the background. Higher values create cleaner object-focused crops. Set to 0.0 to disable background removal. Requires instance segmentation predictions with masks.. | โ |
background_color |
Union[Tuple[int, int, int], str] |
Background color to use when removing background from instance segmentation crops. Only applies when mask_opacity > 0 and predictions contain segmentation masks. Background pixels outside the detected instance mask are replaced with this color. Can be specified as: hex string (e.g., '#431112' or '#fff'), RGB string in parentheses (e.g., '(128, 32, 64)'), or RGB tuple (e.g., (18, 17, 67)). Defaults to black (0, 0, 0). Use white (255, 255, 255) or '#ffffff' for white backgrounds, or match your use case's background requirements. Color values are interpreted as RGB and converted to BGR for image processing.. | โ |
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 Dynamic Crop in version v1.
- inputs:
SAM 3,Image Preprocessing,Time in Zone,Image Slicer,Anthropic Claude,Dynamic Crop,Mask Area Measurement,BoT-SORT Tracker,Bounding Box Visualization,Object Detection Model,Mask Edge Snap,Path Deviation,Absolute Static Crop,SIFT Comparison,Stitch Images,Stitch OCR Detections,OpenAI,Instance Segmentation Model,Email Notification,Stability AI Inpainting,EasyOCR,Llama 3.2 Vision,Track Class Lock,Florence-2 Model,Gaze Detection,Roboflow Custom Metadata,Dynamic Zone,Auto Rotate on Edges,YOLO-World Model,Dominant Color,Byte Tracker,Detections Transformation,Keypoint Detection Model,Stability AI Outpainting,Model Comparison Visualization,Detections Classes Replacement,Slack Notification,Line Counter Visualization,Camera Calibration,Byte Tracker,Single-Label Classification Model,Clip Comparison,VLM As Detector,CogVLM,SORT Tracker,Camera Focus,Corner Visualization,Ellipse Visualization,PP-OCR,Morphological Transformation,Detections List Roll-Up,Anthropic Claude,Roboflow Visual Search,Color Visualization,Instance Segmentation Model,OpenAI,Triangle Visualization,Time in Zone,Detection Event Log,Detections Stabilizer,Object Detection Model,Image Contours,SAM 3,Image Threshold,SAM 3,Detections Merge,Current Time,Roboflow Visual Search Classifier,QR Code Generator,OpenAI-Compatible LLM,Florence-2 Model,Polygon Zone Visualization,Stitch OCR Detections,Path Deviation,Roboflow Asset Library Attributes,Microsoft SQL Server Sink,Moondream2,VLM As Classifier,Camera Focus,Image Convert Grayscale,Label Visualization,Detection Offset,Stability AI Image Generation,Llama 3.2 Vision,VLM As Detector,Instance Segmentation Model,Line Counter,MQTT Writer,Roboflow Dataset Upload,Local File Sink,Identify Outliers,Bounding Rectangle,Google Gemini,Event Writer,Depth Estimation,Seg Preview,Byte Tracker,Google Gemini,OpenAI,Trace Visualization,Twilio SMS Notification,SAM 3 Interactive,Detections Filter,LMM For Classification,Object Detection Model,Velocity,Webhook Sink,Halo Visualization,Mask Visualization,Template Matching,Pixelate Visualization,Twilio SMS/MMS Notification,MoonshotAI Kimi,Dot Visualization,Multi-Label Classification Model,OPC UA Writer Sink,Google Gemini,OC-SORT Tracker,Keypoint Visualization,LMM,Detections Combine,Image Slicer,PTZ Tracking (ONVIF),Time in Zone,OCR Model,Circle Visualization,Contrast Enhancement,Relative Static Crop,SAM2 Video Tracker,ByteTrack Tracker,Morphological Transformation,Per-Class Confidence Filter,Email Notification,Halo Visualization,Cosmos 3,Polygon Visualization,Qwen-VL,PLC Writer,Google Gemma,Crop Visualization,Qwen 3.5 API,Model Monitoring Inference Aggregator,Keypoint Detection Model,Icon Visualization,Heatmap Visualization,Motion Detection,Google Gemma API,Detections Consensus,Instance Segmentation Model,CSV Formatter,SAM3 Video Tracker,Image Blur,Background Color Visualization,Grid Visualization,Detections Stitch,Segment Anything 2 Model,Blur Visualization,GLM-OCR,Anthropic Claude,Reference Path Visualization,Classification Label Visualization,Google Vision OCR,Perspective Correction,Background Subtraction,Polygon Visualization,Contrast Equalization,SIFT,Qwen 3.6 API,Text Display,MoonshotAI Kimi,OpenRouter,Qwen3.5-VL,Roboflow Vision Events,Identify Changes,Keypoint Detection Model,OpenAI,Overlap Filter,S3 Sink,Roboflow Dataset Upload - outputs:
SAM 3,Image Preprocessing,Single-Label Classification Model,Anthropic Claude,Image Slicer,CLIP Embedding Model,Dynamic Crop,Time in Zone,Mask Area Measurement,BoT-SORT Tracker,Bounding Box Visualization,Mask Edge Snap,Object Detection Model,Path Deviation,QR Code Detection,Absolute Static Crop,SIFT Comparison,Stitch Images,Stitch OCR Detections,OpenAI,Instance Segmentation Model,Email Notification,Stability AI Inpainting,Frame Delay,Distance Measurement,EasyOCR,Llama 3.2 Vision,Track Class Lock,Florence-2 Model,Gaze Detection,Roboflow Custom Metadata,Dynamic Zone,Auto Rotate on Edges,YOLO-World Model,Dominant Color,Keypoint Detection Model,Detections Transformation,Byte Tracker,Stability AI Outpainting,Model Comparison Visualization,Detections Classes Replacement,Line Counter Visualization,Camera Calibration,Byte Tracker,Single-Label Classification Model,Clip Comparison,VLM As Detector,CogVLM,SORT Tracker,Corner Visualization,PP-OCR,Camera Focus,Ellipse Visualization,Morphological Transformation,Detections List Roll-Up,Anthropic Claude,Roboflow Visual Search,Instance Segmentation Model,Color Visualization,OpenAI,Time in Zone,Triangle Visualization,Detections Stabilizer,Detection Event Log,Object Detection Model,Image Contours,SAM 3,Image Threshold,SAM 3,Barcode Detection,Detections Merge,Roboflow Visual Search Classifier,Qwen2.5-VL,Florence-2 Model,Semantic Segmentation Model,SmolVLM2,Polygon Zone Visualization,Stitch OCR Detections,Path Deviation,GeoTag Detection,Moondream2,VLM As Classifier,Camera Focus,Image Convert Grayscale,Label Visualization,Llama 3.2 Vision,Stability AI Image Generation,Detection Offset,VLM As Detector,Perception Encoder Embedding Model,Instance Segmentation Model,Line Counter,Roboflow Dataset Upload,VLM As Classifier,Bounding Rectangle,Google Gemini,Event Writer,Semantic Segmentation Model,Depth Estimation,Seg Preview,Byte Tracker,Google Gemini,OpenAI,Trace Visualization,Pixel Color Count,SAM 3 Interactive,Detections Filter,LMM For Classification,Object Detection Model,Velocity,Halo Visualization,Buffer,Mask Visualization,Template Matching,Twilio SMS/MMS Notification,Pixelate Visualization,MoonshotAI Kimi,Dot Visualization,Multi-Label Classification Model,Image Stack,Google Gemini,OC-SORT Tracker,Keypoint Visualization,LMM,Detections Combine,Image Slicer,PTZ Tracking (ONVIF),Time in Zone,OCR Model,Circle Visualization,Contrast Enhancement,Relative Static Crop,SAM2 Video Tracker,ByteTrack Tracker,Morphological Transformation,Per-Class Confidence Filter,Halo Visualization,Clip Comparison,Cosmos 3,Polygon Visualization,Qwen-VL,Google Gemma,Crop Visualization,Qwen 3.5 API,Model Monitoring Inference Aggregator,Qwen3-VL,Qwen3.5,Keypoint Detection Model,Size Measurement,Single-Label Classification Model,Icon Visualization,Heatmap Visualization,Motion Detection,Multi-Label Classification Model,Google Gemma API,Instance Segmentation Model,Detections Consensus,Overlap Analysis,SAM3 Video Tracker,Image Blur,Background Color Visualization,Detections Stitch,Segment Anything 2 Model,Blur Visualization,GLM-OCR,Anthropic Claude,Reference Path Visualization,Classification Label Visualization,Google Vision OCR,Background Subtraction,Perspective Correction,Polygon Visualization,Contrast Equalization,SIFT,Qwen 3.6 API,Text Display,MoonshotAI Kimi,OpenRouter,Qwen3.5-VL,Roboflow Vision Events,OpenAI,Keypoint Detection Model,Multi-Label Classification Model,Overlap Filter,Line Counter,Roboflow Dataset Upload
Input and Output Bindings¶
The available connections depend on its binding kinds. Check what binding kinds
Dynamic Crop in version v1 has.
Bindings
-
input
images(image): Input image(s) to extract cropped regions from. Can be a single image or batch of images. Each image will be processed with corresponding detection predictions to extract bounding box regions. Cropped regions are extracted based on bounding boxes in the predictions. Can also accept previously cropped images from another Dynamic Crop step for nested cropping workflows..predictions(Union[instance_segmentation_prediction,keypoint_detection_prediction,object_detection_prediction]): Detection model predictions containing bounding boxes that define regions to crop from the images. Supports object detection (bounding boxes), instance segmentation (bounding boxes with segmentation masks), or keypoint detection (bounding boxes with keypoints) predictions. Each bounding box in the predictions defines a rectangular region to extract. Predictions must include detection IDs for crop tracking. Multiple detections per image result in multiple crops per image..mask_opacity(float_zero_to_one): Background removal opacity for instance segmentation crops (0.0 to 1.0). Only applies when predictions contain segmentation masks (instance segmentation predictions). Controls how aggressively background pixels outside the detected instance are removed: 0.0 leaves the crop unchanged (no background removal), 1.0 fully replaces background with background_color, values between blend the original crop with the background. Higher values create cleaner object-focused crops. Set to 0.0 to disable background removal. Requires instance segmentation predictions with masks..background_color(Union[string,rgb_color]): Background color to use when removing background from instance segmentation crops. Only applies when mask_opacity > 0 and predictions contain segmentation masks. Background pixels outside the detected instance mask are replaced with this color. Can be specified as: hex string (e.g., '#431112' or '#fff'), RGB string in parentheses (e.g., '(128, 32, 64)'), or RGB tuple (e.g., (18, 17, 67)). Defaults to black (0, 0, 0). Use white (255, 255, 255) or '#ffffff' for white backgrounds, or match your use case's background requirements. Color values are interpreted as RGB and converted to BGR for image processing..
-
output
crops(image): Image in workflows.predictions(Union[object_detection_prediction,instance_segmentation_prediction,keypoint_detection_prediction]): Prediction with detected bounding boxes in form of sv.Detections(...) object ifobject_detection_predictionor Prediction with detected bounding boxes and segmentation masks in form of sv.Detections(...) object ifinstance_segmentation_predictionor Prediction with detected bounding boxes and detected keypoints in form of sv.Detections(...) object ifkeypoint_detection_prediction.
Example JSON definition of step Dynamic Crop in version v1
{
"name": "<your_step_name_here>",
"type": "roboflow_core/dynamic_crop@v1",
"images": "$inputs.image",
"predictions": "$steps.my_object_detection_model.predictions",
"mask_opacity": "<block_does_not_provide_example>",
"background_color": "#431112"
}