# Image ROI

This function block lets you crop a region of interest from an input image using horizontal range sliders. Adjust the `Width` and `Height` sliders to define a rectangular crop; the block outputs the cropped image and the rectangle coordinates for further processing.

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

`Image Any` Provide the source image to be cropped.

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

`Image Any` Cropped image corresponding to the selected rectangle.

`Rectangle` Coordinates of the selected ROI as a rectangle shape.

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

`Width` Horizontal range slider to set left/right crop limits (min and max).

`Height` Vertical range slider to set top/bottom crop limits (min and max).

`Input Image Size (H, W)` Informational label that shows the input image dimensions and updates the sliders' ranges automatically.

h2 id="running-mechanism">⚙️ Running mechanism

When the block receives an input image, it reads the image dimensions and updates the `Width` and `Height` slider ranges to match the image size. The sliders provide integer min/max values which define the crop rectangle. On evaluation the block returns the cropped image and a rectangle shape that represents the ROI.

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

* Dynamic slider ranges that automatically adapt to the connected image size.
* Returns both the cropped image and the rectangle coordinates for downstream use.
* Preserves image channel layout (color or grayscale) in the cropped result.
* Remembers and restores the input image size when saving/loading scenarios (serialization support).

## 📝 Usage instructions <a href="#usage" id="usage"></a>

1. Connect an image-producing block to the `Image Any` input.
2. Observe the `Input Image Size (H, W)` label to confirm dimensions.
3. Adjust the `Width` slider min/max to set horizontal crop bounds.
4. Adjust the `Height` slider min/max to set vertical crop bounds.
5. Use the outputs where needed: pass the cropped image to analysis blocks or use the rectangle coordinates for visualization.

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

* To visually inspect the selected ROI while tuning sliders, send the `Image Any` output to the `Show Image` block.
* If the input image is very large, place an `Image Resizer` block before this block to speed up interactive slider adjustments.
* Use `Image ROI Select` or `Image ROI Select Multi` if you prefer selecting crop areas with the mouse instead of sliders, then feed the resulting rectangle into this block or use its outputs downstream.
* For focused detection on the cropped area, feed the cropped image into detector blocks such as `Find Object`, `Object Detection`, or `Blob Detector` to reduce false matches and speed up processing.
* To save examples of the ROI or log them, connect the cropped image output to `Image Logger` or `Image Write`.
* To mark the ROI on the original image for visualization, use the rectangle output with `Draw Rectangle` and then preview using `Show Image`.
* Combine with `Histogram On Line` or `Histogram On Curve` for profile analysis limited to the cropped area.
* Use the rectangle coordinates with ROI-aware blocks like `Get ROI` or `Check Area` to build downstream logic based on object positions inside the selected region.

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

* If sliders do not cover the full image extent, confirm an image is connected and visible in the `Input Image Size (H, W)` label — the sliders update only after the image is received.
* If the cropped output is empty or black, ensure the slider min/max values define a non-zero area and are within image bounds.
* If downstream blocks expect a specific channel format (grayscale vs RGB), use color conversion or an `Image Resizer` / preprocessing block before or after cropping to match expected input formats.


---

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