# Contour to Image

This function block extracts a rectangular image region around a given contour. Provide a source image and a contour (shape) and the block returns a cropped rectangular image that contains the contour. It is useful when you want to isolate and inspect a single object detected in a larger picture.

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

* `Image` — Source image that contains the object to be cropped. Can be color or grayscale.
* `Contour` — Shape/contour describing the object boundary. Provide a contour obtained from a contour-finding or shape-processing block.

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

* `Image` — Cropped rectangular image containing the area around the provided contour.

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

* `No Controls` — This block has no interactive widgets. It works by receiving its inputs and producing the cropped image automatically.

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

When the block runs it looks at the provided contour and determines a rectangular area that encloses the contour. That area is extracted from the source image and returned as the block output. If the contour is rotated or irregular, the block fits a rectangle that contains the contour and returns a rectangular crop so you can continue downstream processing more easily.

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

* Extracts a focused rectangular image around a contour so further analysis becomes simpler.
* Works with contours produced by various detection and shape-analysis blocks.
* Returns a ready-to-use image output for visualization, recognition, or saving.

## 📝 How to use <a href="#usage" id="usage"></a>

1. Produce contours from your image (for example by thresholding and contour detection).
2. Connect the source image to the `Image` input and the chosen contour to the `Contour` input.
3. The block outputs the cropped rectangular image at the `Image` output. Use it as input for other blocks (e.g., recognition, OCR, or saving).

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

* To generate contours before this block, use the `Find Contour` block.
* If you need a simplified polygon before cropping, try `Approximate Contour` to reduce corner count.
* For rotated objects, compare results with `Minimum Rotated Rectangle` or `Minimum Rectangle` to choose the best enclosing shape for your workflow.
* Preview the cropped result quickly with the `Show Image` block.
* After cropping, you can apply `Image Resize` to normalize sizes, or `Auto Contrast` / `Denoising` to prepare the crop for downstream tasks.
* To save crops automatically, connect this block's output to `Image Logger` or `Image Write`.

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

* If the output is unexpected or empty, verify that the `Contour` input contains a valid contour (not `None`). Use `Find Contour` or `Approximate Contour` to produce valid contours.
* If the crop looks clipped, check that the contour coordinates lie within the source image bounds. Adjust preprocessing or contour selection if necessary.
* If the object appears rotated or skewed and you need a different perspective, experiment with `Minimum Rotated Rectangle` or use a perspective-aware workflow (crop then `Auto Alignment` / `Perspective Transform`) before further analysis.


---

# 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/shape-analysis/contour-to-image.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.
