# Taxonomy for polygons

**URL:** <https://community.labelstud.io/t/taxonomy-for-polygons/416>\
**Category:** Label Studio Support\
**Tags:** annotations\
**Created:** [November 22, 2024, 6:25pm UTC](https://community.labelstud.io/t/taxonomy-for-polygons/416 "2024-11-22T18:25:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![GeoJeff](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.labelstud.io/geojeff/32/211_2.png) [@GeoJeff](https://community.labelstud.io/u/GeoJeff)\
**Post date:** [November 22, 2024, 6:25pm UTC](https://community.labelstud.io/t/taxonomy-for-polygons/416/1 "2024-11-22T18:25:31Z")

</div>

Howdy, fairly new to label studio. I’m starting image annotation for a computer vision project. Is there a way to have nested levels of polygon labels or attributes attached to those polygons easily? I’m looking for something like taxonomy, only for polygons instances.

I’m working on label studio 1.13.1 installed through pip with a sqllite default backend.

Example: I’m working to identify types of fences and damage to them. I could use nested labels like:  
Fence type: metal, wood, vinyl.  
For each fence type there could be subclasses like: no damage, vines, structural damage. For certain classes there might be other attributes: metal: rust.

Most items would be the primary class and no damage, I.e: wood: no damage.

If there’s an easy or common way to solve this problem, even if it’s not attributes or subclasses, I’d be interested in hearing it.

I see there’s a metadata option, but it appears to be free text only. I’d rather have set options to avoid typos.

---

<div class="post-metadata">

**Author:** ![makseq](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.labelstud.io/makseq/32/26_2.png) [@makseq](https://community.labelstud.io/u/makseq)\
**Post date:** [November 26, 2024, 11:38pm UTC](https://community.labelstud.io/t/taxonomy-for-polygons/416/2 "2024-11-26T23:38:02Z")

</div>

Hello!

Yes, you can achieve nested levels of labels or attach attributes to polygons in Label Studio by using the `perRegion` attribute in combination with `Choices` tags. This allows you to associate additional labels or attributes with each polygon you draw on the image.

Here’s how you can set this up:

1. **Use `PolygonLabels` to annotate the fences** : This lets annotators draw polygons around the fences and assign the main fence type (metal, wood, vinyl).
2. **Use `Choices` with `perRegion="true"`** to attach attributes to each polygon: This allows annotators to select attributes like damage type for each fence polygon.
3. **Conditional visibility** : You can use the `visibleWhen` and `whenLabelValue` attributes to show certain choices only when specific labels are selected.

Here’s an example of how your labeling configuration might look:

```auto
<View>
  <Image name="image" value="$image"/>

  <!-- Main fence type labels -->
  <PolygonLabels name="fence_type" toName="image">
    <Label value="Metal"/>
    <Label value="Wood"/>
    <Label value="Vinyl"/>
  </PolygonLabels>

  <!-- Generic damage types applicable to all fences -->
  <Choices name="damage_type" toName="image" perRegion="true" choice="single-radio" showInline="true">
    <Header value="Damage Type"/>
    <Choice value="No Damage"/>
    <Choice value="Vines"/>
    <Choice value="Structural Damage"/>
  </Choices>

  <!-- Specific attribute for Metal fences -->
  <Choices name="metal_attributes" toName="image" perRegion="true" choice="single-radio" showInline="true"
           visibleWhen="region-labels" whenLabelValue="Metal">
    <Header value="Metal Fence Attributes"/>
    <Choice value="Rust"/>
  </Choices>
</View>

```

**Explanation:**

- **`PolygonLabels`** : Allows annotators to draw polygons and assign one of the fence types to each polygon.
- **`Choices` with `perRegion="true"`** : Associates the selected damage type with the currently selected polygon region.
- **Conditional Visibility** : The `metal_attributes` `Choices` tag is only visible when the polygon has the label “Metal”, using `visibleWhen="region-labels"` and `whenLabelValue="Metal"`. This way, the “Rust” option appears only for metal fences.

**Avoiding Typos:**

By using predefined options in the `Choices` tags, you eliminate the need for free text entry, thus avoiding typos and ensuring consistent data.

**Additional Tips:**

- **Unique `name` Attributes** : Ensure that each control (`PolygonLabels`, `Choices`, etc.) has a unique `name` attribute.
- **Order of Tags** : Place the `Choices` tags after the `PolygonLabels` in the configuration to ensure they appear appropriately in the interface.
- **Extending Attributes** : For other specific attributes (e.g., attributes unique to wood or vinyl fences), you can add additional `Choices` tags with conditional visibility using the respective `whenLabelValue`.

**Resources:**

- [PolygonLabels Tag Documentation](https://labelstud.io/tags/polygonlabels.html)
- [Choices Tag Documentation](https://labelstud.io/tags/choices.html)
- [Conditional Tag Appearance Guide](https://labelstud.io/guide/setup.html#Conditional-Tag-Appearance)

**Example Workflow:**

1. **Annotator draws a polygon** around a fence in the image.
2. **Annotator selects the fence type** (Metal, Wood, Vinyl) for that polygon.
3. **Damage Type choices appear** for the annotator to select, attached to that polygon.
4. **If “Metal” is selected** , the “Metal Fence Attributes” choices (like “Rust”) become visible for the annotator to choose.

---

<div class="post-metadata">

**Author:** ![GeoJeff](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.labelstud.io/geojeff/32/211_2.png) [@GeoJeff](https://community.labelstud.io/u/GeoJeff)\
**Post date:** [December 2, 2024, 8:56pm UTC](https://community.labelstud.io/t/taxonomy-for-polygons/416/3 "2024-12-02T20:56:27Z")

</div>

This works great. Thank you!

For anyone else who comes across this, I also experimented with generic ‘Labels’ instead of ‘PolygonLabels’ and added in the polygon, brush and magic wand tools. Those also work with the choice class the same way.
