Skip to content

Dynamic Crop

Version v1

Create dynamic crops from an image based on detections from detections-based model.

This is useful when placed after an ObjectDetection block as part of a multi-stage workflow. For example, you could use an ObjectDetection block to detect objects, then the DynamicCropBlock block to crop objects, then an OCR block to run character recognition on each of the individual cropped regions.

In addition, for instance segmentation predictions (which provide segmentation mask for each bounding box) it is possible to remove background in the crops, outside of detected instances. To enable that functionality, set mask_opacity to positive value and optionally tune background_color.

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 The unique name of this step..
mask_opacity float For instance segmentation, mask_opacity can be used to control background removal. Opacity 1.0 removes the background, while 0.0 leaves the crop unchanged..
background_color Union[Any, str] For background removal based on segmentation mask, new background color can be selected. Can be a hex string (like '#431112') RGB string (like '(128, 32, 64)') or a RGB tuple (like (18, 17, 67))..

The Refs column marks possibility to parametrise the property with dynamic values available in workflow runtime. See Bindings for more info.

Available Connections

Check what blocks you can connect to Dynamic Crop in version v1.

The available connections depend on its binding kinds. Check what binding kinds Dynamic Crop in version v1 has.

Bindings
  • input

    • images (image): The input image for this step..
    • predictions (Union[object_detection_prediction, keypoint_detection_prediction, instance_segmentation_prediction]): The output of a detection model describing the bounding boxes that will be used to crop the image..
    • mask_opacity (float_zero_to_one): For instance segmentation, mask_opacity can be used to control background removal. Opacity 1.0 removes the background, while 0.0 leaves the crop unchanged..
    • background_color (Union[rgb_color, string]): For background removal based on segmentation mask, new background color can be selected. Can be a hex string (like '#431112') RGB string (like '(128, 32, 64)') or a RGB tuple (like (18, 17, 67))..
  • output

    • crops (image): Image in workflows.
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"
}