# Image ROI Polygon Multi

This function block lets you draw and save multiple polygonal regions of interest (ROIs) directly on an image. Use it to highlight areas, crop multiple irregular regions, and export each polygon as a separate image for further processing.

## 📥 Inputs <a href="#inputs" id="inputs"></a>

* `Image` Image to annotate and extract polygons from.

## 📤 Outputs <a href="#outputs" id="outputs"></a>

* `Highlighted Image` The original image annotated with saved polygons and current drawing overlay.
* `Polygon Images` List of cropped image regions for each saved polygon.
* `Polygons` List of polygon coordinate sets (shape data) describing each saved polygon.

## 🕹️ Controls <a href="#controls" id="controls"></a>

* `Image Area` Clickable image canvas where you draw polygons with the mouse.
* `Left mouse click` Add a vertex to the current polygon.
* `S` Save the current polygon (must have at least three points).
* `U` Undo last point or enter edit mode for the last saved polygon.
* `C` Clear the current polygon or remove the last saved polygon.
* `Info` On-block help text reminding you of the key controls and shortcuts.

## 🎨 Features <a href="#features" id="features"></a>

* Interactive drawing: create polygons by clicking directly on the image.
* Multi-polygon support: save and manage several polygons in the same image.
* Edit and undo: recover the last saved polygon for adjustment with the `U` shortcut.
* Visual overlays: saved polygons are highlighted and numbered; current polygon shows live preview.
* Cropped outputs: each saved polygon is exported as an individual image ready for downstream processing.
* Efficient caching: avoids unnecessary redraws when image and polygons are unchanged.

## ⚙️ Running mechanism <a href="#running-mechanism" id="running-mechanism"></a>

* Feed an `Image` into the block. The image appears on the interactive canvas.
* Draw a polygon by left-clicking successive vertices. A live overlay shows lines and filled preview for the current polygon.
* Press `S` to save a completed polygon (minimum three points). Saved polygons become part of the `Highlighted Image` and appear in the `Polygon Images` and `Polygons` outputs.
* Use `U` to undo the last point (or to edit the last saved polygon). Use `C` to clear the current drawing or delete the last saved polygon.
* The block returns the annotated image, the list of cropped polygon images, and the polygon coordinate data whenever evaluated.

## 💡 Tips and Tricks <a href="#tips-and-tricks" id="tips-and-tricks"></a>

* To preview the result in a larger window, combine with the `Show Image` block: feed this block's `Highlighted Image` to `Show Image` for an expanded viewer.
* If you need rectangular ROIs instead of polygons, try the `Image ROI Select` or `Image ROI Select Multi` blocks for quick rectangle drawing.
* Use `Get ROI` if you want to apply other blocks to rectangular crops derived from polygon bounding boxes.
* For applying the polygon as a binary mask and filtering the image content, pair with `Apply Mask`. Feed the polygon image into `Mask` and the original image into `Image` to extract only the polygon area.
* To analyze features inside a polygon (for instance, line peaks), crop the polygon output and connect it to `Histogram On Line` or `Histogram On Curve`.
* For detection pipelines, send each `Polygon Images` output into `Find Object`, `Object Detection`, or `Object Detection - Custom` to run matching/detection only inside selected areas.
* Save results automatically using `Image Logger` or `Image Write` by connecting them to the relevant cropped images.
* If your source image is large, use `Image Resizer` before drawing to speed up interaction, then map polygon coordinates back to the original if needed.

## 🛠️ Troubleshooting <a href="#troubleshooting" id="troubleshooting"></a>

* Nothing appears on the canvas: ensure an `Image` is connected and the block has been run at least once.
* Saved polygon not exported correctly: confirm the polygon had at least three points before saving with `S`.
* Cropped polygon looks shifted or clipped: check image aspect ratio and any resizing blocks upstream. If you resize before drawing, keep track of scale when using crops downstream.
* Too slow with many polygons: reduce image resolution with `Image Resizer` while drawing, or limit the number of saved polygons. Use the block’s outputs to store only the required polygon images.


---

# Agent Instructions: Querying This Documentation

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

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.augelab.com/function-blocks/detections-shapes/roi-processing/image-roi-polygon-multi.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
