> For the complete documentation index, see [llms.txt](https://docs.augelab.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.augelab.com/function-blocks/blocks-reference/detections-shapes/shape-analysis/contour-to-image.md).

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