> For the complete documentation index, see [llms.txt](https://docs.eyepop.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.eyepop.ai/platform/pop/pop-components/mask-operations.md). Agents can also search and read this documentation through its [MCP server](https://docs.eyepop.ai/~gitbook/mcp).

# Mask Operations

The contour finder and component finder, which turn segmentation masks into shapes and objects

Two component types work on the segmentation masks an inference component produced. Neither runs inference. Place one on a forward from a segmentation component.

## `contour_finder`

Converts segmentation masks into contours.

| Attribute       | Type   | Description                                                                                                                                                                                              |
| --------------- | ------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `contourType`   | string | The shape to fit. Optional — defaults to `polygon`. One of `polygon`, `all_pixels`, `convex_hull`, `hough_circles`, `circle`, `triangle`, or `rectangle`.                                                |
| `areaThreshold` | float  | Discards contours covering less than this fraction of the source's total pixels — `0.01` drops anything under 1% of the source. Applies to `polygon` and `all_pixels` only; the fitted shapes ignore it. |

Contours always come back as polygons, even for `circle` and `rectangle`. `all_pixels` and `polygon` can contain cut-outs; the fitted shapes cannot.

## `component_finder`

Splits one segmentation mask into separate sub-objects using connected components — the way to turn a single "cell colony" mask into a count of individual cells.

| Attribute             | Type    | Description                                                                              |
| --------------------- | ------- | ---------------------------------------------------------------------------------------- |
| `componentClassLabel` | string  | Class label applied to each sub-object found. Defaults to the source object's own label. |
| `erode`               | float   | Shrinks the mask before splitting. `0.0`–`1.0`, default `0.0` (off).                     |
| `dilate`              | float   | Grows the mask before splitting. `0.0`–`1.0`, default `0.0` (off).                       |
| `keepSource`          | boolean | Keeps the original mask in the result alongside the sub-objects.                         |

### How `erode` and `dilate` reshape the mask

Both are classic morphological operations applied to the mask **before** components are counted, so they change how many sub-objects you get.

* **`erode`** peels pixels off the mask's edges. Thin bridges between blobs that are really separate objects break, and each blob shrinks. This is what turns one mask of touching cells into a count of individual cells.
* **`dilate`** adds pixels around the mask's edges. Nearby fragments merge, and gaps and pinholes close. This is what stops one speckled object from being counted as many.

Two details decide what a value actually does:

**The value is a fraction of the mask's own size, not the frame's.** Each kernel axis is `round(factor × mask_extent ÷ 2)` pixels, so `0.1` on a mask 200 pixels wide gives a kernel 10 pixels across. Because it scales with the mask, the same factor behaves consistently on objects of different sizes. The kernel is elliptical, so the effect is even in all directions rather than boxy.

A factor small enough to round either axis below one pixel is treated as a no-op rather than a smaller kernel — both axes decide that together, so a sub-pixel request never applies to one axis only because the mask happens to be tall and narrow.

**Order is fixed: `erode` runs first, then `dilate`.** Setting both is therefore a morphological *opening*: erosion severs the thin connections and drops specks, then dilation restores the surviving blobs to roughly their original size. That is usually what you want for counting — separation without shrinking everything you kept. Setting them expecting dilation to undo the erosion will not work; the pixels erosion removed are gone before dilation runs.

Start with `erode` alone when objects are merged, `dilate` alone when one object is fragmenting into several, and both when you need separation without losing size.

## Next steps

* [Components](https://docs.eyepop.ai/platform/pop/pop-components.md) — the other component types and the shared attributes
* [Masks, contours and depth](https://docs.eyepop.ai/platform/response-format/predictions/masks-contours-and-depth.md) — how masks and contours come back in the response
* [Examples](https://docs.eyepop.ai/platform/pop/pop-examples.md) — splitting a mask into sub-objects, end to end


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.eyepop.ai/platform/pop/pop-components/mask-operations.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
