Skip to navigation

Crop objects

Overview

Crops object detection labels from images in a source dataset and saves each crop as a new image asset.

Crops are always written to the node’s own LAST_RUN dataset, a new version of it on every rerun. When a destination dataset is provided, the same crops and crop annotations are also added there.

Use it when object detection annotations are available and the next step needs cropped object images.

Dataset Create ontology Crop objects Dataset

Prerequisites

RequirementWhat you need
Rectangle labelsObjects with rectangle (bounding-box) annotations. Other geometries are skipped.

How it works

1

Reads each image and its latest annotation from the source dataset.

2

Crops every rectangle label, optionally limited to the selected classes and expanded by the configured padding.

3

Tags each crop with its class, taken from the object class or from a label tag when Class Tag is set.

4

Writes the crops to the LAST_RUN dataset, and also to the destination dataset when one is provided.

FAQ

Rectangle (bounding-box) labels only. Other geometry types are skipped. Leave Classes empty to crop every class, or list specific class names.

Enter padding as a comma-separated list of pixels or percentages, for example 10px,5%,10px,5%, ordered top, right, bottom, left. Leave it empty for no padding.

It sets each crop’s class from a label tag value instead of the object class name. For example, use a number tag to label number-plate crops by their value.

Always to the node’s own LAST_RUN dataset, and also to the destination dataset when you connect one.

The source dataset has no supported rectangle labels for the selected classes. Check the annotations and the Classes filter.

Every crop asset carries its provenance in its metadata, so one asset read resolves it:

KeyValue
source_asset_idAsset ID of the image the crop was taken from.
source_dataset_idDataset ID that image belongs to.
source_bbox"left,top,right,bottom" in pixels of the source image, before padding and before clamping to the image edge. right and bottom are inclusive, as Supervisely rectangles are.
source_classObject class of the crop, the same value written as the crop annotation’s image tag.

These live in metadata rather than tags: source_asset_id and source_bbox hold a distinct value per crop, which would flood the tag filter dropdown. Metadata is not a search filter surface, so it is read back per asset, not queried across a dataset.

Inputs

From dataset
datasetRequired

Source dataset the crops are cut from. Only rectangle annotations become crops. Key: SRC_DATASET.

To dataset
dataset

Destination dataset the crops are added to. Leave empty to keep them only in the node’s own crops dataset. Key: DST_DATASET.

Classes
ontology

Class names to crop. Leave empty to crop all classes. Values come from SRC_DATASET. Key: CLASSES.

Paddings (px or %)
string

Extra space kept around each object, in pixels or as a percentage of its size, for example 10px or 10px,5%,10px,5%. Four values are read as top, right, bottom, left. Key: PADDINGS.

Class tag
string

Name a tag on the object, and its value becomes the class of the crop - a “number” tag turns a number plate into a crop of that number. Leave empty to use the object’s own class. Key: CLASS_TAG.

Outputs

Dataset
dataset

ID of the dataset with cropped assets. Key: DATASET.

Crops
dataset

Dataset with the crops of the latest run. A rerun writes a new version of it. Shown as an artifact. Key: LAST_RUN.

JSON config

Machine-readable node interface for automation and advanced usage.

{
"name": "Crop objects",
"description": "Crops objects from images in the source dataset based on their annotations and saves them as new assets in the destination dataset.",
"category": "Assets",
"namespace": "ovalbee",
"templateKey": "asset_ops/crop_objects",
"version": "v1",
"inputs": [
{
"key": "SRC_DATASET",
"label": "From dataset",
"type": "dataset",
"description": "Source dataset the crops are cut from. Only rectangle annotations become crops.",
"required": true,
"default": null,
"visibleWhen": null,
"options": {
"creatable": false
}
},
{
"key": "DST_DATASET",
"label": "To dataset",
"type": "dataset",
"description": "Destination dataset the crops are added to. Leave empty to keep them only in the node's own crops dataset.",
"required": false,
"default": null,
"visibleWhen": null
},
{
"key": "CLASSES",
"label": "Classes",
"type": "ontology",
"description": "Class names to crop. Leave empty to crop all classes.",
"required": false,
"default": null,
"visibleWhen": null,
"options": {
"ref": "SRC_DATASET",
"selectable": true
}
},
{
"key": "PADDINGS",
"label": "Paddings (px or %)",
"type": "string",
"description": "Extra space kept around each object, in pixels or as a percentage of its size, for example 10px or 10px,5%,10px,5%. Four values are read as top, right, bottom, left.",
"required": false,
"default": null,
"visibleWhen": null
},
{
"key": "CLASS_TAG",
"label": "Class tag",
"type": "string",
"description": "Name a tag on the object, and its value becomes the class of the crop - a \"number\" tag turns a number plate into a crop of that number. Leave empty to use the object's own class.",
"required": false,
"default": null,
"visibleWhen": null
}
],
"outputs": [
{
"key": "DATASET",
"label": "Dataset",
"type": "dataset",
"description": "ID of the dataset with cropped assets.",
"artifact": false,
"badge": false,
"badgeOpens": null,
"hidden": false
},
{
"key": "LAST_RUN",
"label": "Crops",
"type": "dataset",
"description": "Dataset with the crops of the latest run. A rerun writes a new version of it.",
"artifact": true,
"badge": false,
"badgeOpens": null,
"hidden": false
}
]
}