# Annotation

## Annotation

An image is composed of array of pixels, and we have two ways to annotate on the pixels, by using the `segmentation` tool (as RLE - run-length encoding) and `vector` tool.

### Segmentation (RLE)

RLE (run-length encoding) object is used only when the label type is `segmentation`, and each label contains only one RLE object. When annotating with RLE, we basically annotate the pixel in the image:

<div align="center"><img src="https://776641706-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MEzwb1apIVYCtVsgB9Y%2F-MFspbkJkiU8E7msmH8W%2F-MFsr9461RvMil0h3916%2F90091229-73ed1800-dd58-11ea-9c41-59f8d272cbad.png?alt=media&#x26;token=fd937f20-32cf-4fb7-bfa5-5dea06c4e380" alt=""></div>

An RLE object is represented as:

```
{
  "type": STRING,
  "segmentation": [
    [x, y, length from x to right],
    ...
  ]
}
```

* **type**: Type of the segmentation, which currently supports `rle` only.
* **segmentation**: Two-dimensional array for RLE.
  * The minimal unit of segmentation is a 1x1 pixel area, which is an integer.
  * For example, given by the 4x4 pixel image below with annotation, the array will be:

```
{
  "segmentation": [
    [2, 0, 2],
    [0, 1, 3],
    [2, 2, 1]
  ]
}
```

&#x20;

![](https://776641706-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MEzwb1apIVYCtVsgB9Y%2F-MFspbkJkiU8E7msmH8W%2F-MFss-VXeB89_z9uMQZ8%2F90091317-9da63f00-dd58-11ea-94e1-a026179baa8a.png?alt=media\&token=d1a6b7f4-6cf4-44fb-a037-cc345566634a)

### vector

A vector object is used only when the label type is `vector`, and each label can contain multiple vector objects. When annotating with vector, we basically describe the coordinates of the annotation in the image:

![](https://776641706-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MEzwb1apIVYCtVsgB9Y%2F-MFspbkJkiU8E7msmH8W%2F-MFssAMnbdv3fbUGJ8aU%2F90106189-a52a1000-dd79-11ea-8c26-ec9afb42ded3.png?alt=media\&token=d75c0313-1079-4a2c-93b6-2c4ce8434ff2)

A vector object is represented as:

```
{
  "type": STRING,
  "attributes": [
    {
      "name": STRING,
      "values": [STRING]
    }
  ],
  "segmentation": [x1, y1, x2, y2, ..., xn, yn]
}
```

* **type**: Type of the vector object, currently supports `polygon`, `boundingBox`, `path` and `point`.
* **attributes**: Custom attributes to describe the vector object.
  * **name**: Name of the attribute.
  * **values**: Array of value to the attribute.
* **segmentation**: Array of coordinate which represents the vector object.

  * The minimal unit of segmentation is a coordinate, which is float.
  * if the segmentation type is `polygon`, the value will be `[x1, y1, x2, y2, ..., xn, yn]`.
  * if the segmentation type is `boundingBox`, the value will be `[x1, y1, x2, y2, x3, y3, x4, y4]`.
  * if the segmentation type is `path`, the value will be `[x1, y1, x2, y2, ..., xn, yn]`.
  * if the segmentation type is `point`, the value will be `[x1, y1]`.
  * The coordinates can be either clockwise or counterclockwise as long as it follows the order.
  * For example, given by the 4x4 pixel images below with annotation, the array will be:

  &#x20;

![](https://776641706-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MEzwb1apIVYCtVsgB9Y%2F-MGDAW0CeC7zU0j86EBB%2F-MGDBUPUkflLwNWZ1I8s%2F90107448-68f7af00-dd7b-11ea-87c6-e0875d7ff79a%20\(1\).png?alt=media\&token=bb300e2a-7e86-41cb-b9b4-2ba3fe1ab2c8)

![](https://776641706-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MEzwb1apIVYCtVsgB9Y%2F-MGDAW0CeC7zU0j86EBB%2F-MGDBbMWY4SxSnuhK_YC%2F90107831-0226c580-dd7c-11ea-9f6f-d714bc0fc883%20\(1\).png?alt=media\&token=c06f178a-acd5-4d3c-87f7-40e8ca4deaa6)
