# Line Detector

This function block detects and highlights straight lines in an input image. It offers simple controls to guide the detection toward a preferred orientation, tune sensitivity, and pick a single "selected" line according to different selection modes. The block also produces a histogram visualization of intensity values along the chosen line to help with further analysis.

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

`Image Any` Image to analyze for line structures (color or grayscale).

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

`Lined Image` Image with detected lines visualized.

`Histogram Image` Intensity histogram image with optional overlay showing statistics for the selected line.

`Number of Lines` Count of detected lines after any filtering.

`Selected Line` A single selected line (shape) chosen according to the selected selection mode.

`Lines` All detected lines (shapes), returned as a list when applicable.

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

`Preferred Angle` Choose the orientation (in degrees) you are most interested in (0–180). This biases detection toward lines with that orientation.

`Tolerance (deg)` Set how much deviation from the preferred angle is allowed. Smaller values restrict detection to lines close to the preferred orientation.

`Line Selection` Pick how to choose the single representative line from multiple detections. Options include First Position, Last Position, Longest, Shortest, Middle Position, and Median Length.

`Hough Threshold (Votes)` Adjust sensitivity for line detection. Higher values make detection stricter (fewer lines); lower values detect weaker lines.

`Min. Line Length (pixels)` Ignore very short segments by setting a minimum length for detected lines.

`Max. Line Gap (pixels)` When using segment-based detection, this controls how far apart broken segments may be to still be joined into a single line.

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

* The input image is prepared for line analysis (converted and enhanced as needed).
* Prominent edges and segments are located across the image.
* Detected segments are collected and (optionally) filtered to keep those close to the `Preferred Angle` within the `Tolerance (deg)`.
* One line is selected based on the `Line Selection` control.
* The result image is rendered with all found lines shown and the selected line highlighted.
* A histogram image of intensity values is produced; if a line is selected, the histogram will also show basic statistics (mean, optionally standard deviation) for pixels sampled along that line.

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

* Visual output that draws all detected lines and highlights a chosen line for easy inspection.
* Flexible selection modes to choose a single line that best fits your task.
* Angle-based filtering to focus on a desired orientation.
* Simple histogram output tied to the chosen line for quick intensity analysis.
* Adjustable parameters to trade off sensitivity vs noise tolerance.

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

1. Connect an image-producing block to the `Image Any` input (for example, a camera or an image loader).
2. Set `Preferred Angle` to the orientation you expect in the scene.
3. Reduce `Tolerance (deg)` to focus tightly on that orientation, or increase it to accept more varied angles.
4. Tune `Hough Threshold (Votes)`, `Min. Line Length`, and `Max. Line Gap` to find a balance between missing weak lines and including noise.
5. Use `Line Selection` to pick the single line representation that makes sense for your task.
6. Inspect the `Lined Image` and `Histogram Image` outputs; use the line shapes for downstream processing.

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

* For noisy images, add a `Blur` block before this block to smooth noise and improve detection stability.
* If your source images are very large, use `Image Resize` to lower resolution and speed up detection while keeping meaningful structures.
* To focus processing on a particular region, crop first with `Image ROI Select` or `Get ROI` then run this block on the cropped image.
* After detection, combine the `Selected Line` or `Lines` outputs with `Line Geometry` to measure angles, distances, intersections or extract coordinates.
* For visual debugging, feed the `Lined Image` into `Show Image` to view results in a larger viewer, or save examples using `Image Logger` or `Image Write`.
* Use `Histogram On Line` when you need more specialized peak analysis along a single straight scan line; it complements the histogram produced here.
* To draw or annotate specific measurement lines interactively, combine with `Draw Line` and then analyze the drawn line with this block.

(hints above use only blocks from the provided list)

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

* No lines detected: Lower `Hough Threshold (Votes)`, decrease `Min. Line Length`, or increase `Tolerance (deg)` so more candidates are accepted.
* Too many spurious lines: Increase the `Hough Threshold (Votes)` or raise `Min. Line Length` to ignore small noisy segments.
* Selected line is unexpected: Try different `Line Selection` modes (e.g., Longest or Middle Position) or adjust the preferred angle and tolerance.
* Histogram seems unrelated to the selected line: Ensure the selected line lies fully inside the image area; crop with `Image ROI Select` if necessary.

If you need more stable results in production, preprocess images (lighting, contrast) and test parameter ranges on representative samples before deploying.


---

# 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/detectors/line-detector.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.
