> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.ovalbee.com/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.ovalbee.com/_mcp/server.

# Crop objects

> Crops objects from images in the source dataset based on their annotations and saves them as new assets in the destination dataset.

## 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.

```mermaid
flowchart LR
  n1["Dataset"] --> n2["Create ontology"] --> n3["Crop objects"] --> n4["Dataset"]
```

## Prerequisites

| Requirement          | What you need                                                                    |
| -------------------- | -------------------------------------------------------------------------------- |
| **Rectangle labels** | Objects with rectangle (bounding-box) annotations. Other geometries are skipped. |

## How it works

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

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

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

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

## FAQ

#### Which objects get cropped?

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

#### How does padding work?

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.

#### What does Class Tag do?

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.

#### Where do the crops go?

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

#### Why did the run fail with no crops?

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

#### How do I find the source image of a crop?

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

| Key                 | Value                                                                                                                                                                             |
| ------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `source_asset_id`   | Asset ID of the image the crop was taken from.                                                                                                                                    |
| `source_dataset_id` | Dataset 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_class`      | Object 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`** `dataset` — required

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.

#### Show JSON

```json
{
  "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
    }
  ]
}
```