# Most Similar Shape

This function block compares a reference contour against a list of candidate contours and selects the most similar one. It returns the best-matching contour, a similarity score (0-1), and an annotated image showing the selected contour.

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

* `Contour` Reference contour used for comparison
* `Contour(s)` List of candidate contours to compare against
* `Image` Optional image used for visual output/annotation

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

* `Most Similar` The contour from the candidate list that best matches the reference
* `Score (0-1)` Similarity score (1.0 means identical, lower values indicate less similarity)
* `Image Any` Optional annotated image with the selected contour highlighted

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

This function block has no user-configurable controls. It runs automatically when inputs are provided.

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

* Fast comparison of shapes to find the closest match in a list.
* Produces both a numeric similarity score and a visual result for verification.
* Works with any contour format accepted by the system.

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

1. Provide a reference contour to `Contour` input.
2. Provide one or more candidate contours to `Contour(s)` input.
3. Optionally supply an image to `Image` to receive an annotated visual showing which contour was chosen.
4. Run the scenario; outputs will include the selected contour, its similarity score, and the annotated image if supplied.

## 📊 Evaluation <a href="#evaluation" id="evaluation"></a>

When evaluated, this block measures resemblance between the reference contour and each candidate. It returns the candidate with the best resemblance (highest similarity) along with a numeric score and an annotated image (if provided).

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

* To extract contours from a binary image first, use `Find Contour` to get contours suitable for comparison.
* Use `Approximate Contour` to simplify contours (reduce point count) before comparison when shapes are noisy or overly detailed.
* Combine with `Hull Convex` to compare convex hulls instead of raw contours when outer shape similarity is desired.
* Use `Minimum Rectangle`, `Minimum Ellipse`, or `Minimum Circle` to convert contours into simple geometric descriptors for alternate comparison strategies.
* Preprocess input images with `Blur`, `Denoising`, or `Image Threshold` to reduce noise and improve contour extraction.
* If you want to visually inspect the selected result, connect the annotated image output to `Show Image`.
* Use `Contour to Image` to crop or isolate the region around a contour for further inspection or downstream processing.
* Draw the selected contour on live output using `Draw Result On Image` or `Draw Detections` for clearer visualization in dashboards.
* If you only need to compare contours within a sub-area, crop first with `Image ROI` or `Image ROI Select` to limit candidates and speed up processing.
* For batch comparisons over multiple regions, use `Image ROI Polygon` or `Image ROI Polygon Multi` to generate multiple areas and feed their contours into this block.

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

* If similarity scores are unexpectedly low, ensure contours are extracted from a clean binary image (use `Image Threshold` and `Blur` as needed).
* If multiple candidates produce similar scores, simplify contours with `Approximate Contour` or compare bounding shapes (`Minimum Rectangle`, `Minimum Ellipse`) to reduce sensitivity to small differences.
* If the visual output does not show the selected contour, verify an image was provided to the `Image` input or connect the block output to `Show Image` for preview.


---

# 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/most-similar-shape.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.
