# Auto Contrast

This function block automatically adjusts image contrast by analyzing the image histogram and stretching pixel values to enhance visibility. It is ideal for quickly improving brightness and contrast of photos or camera frames without manual curve edits.

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

`Image Any` — Input socket that accepts the image to be contrast-adjusted.

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

`Image Any` — Output socket that provides the contrast-enhanced image.

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

`Threshold` — Slider to set histogram clipping percentage (range typically 1–99). Higher values clip more extremes before stretching, producing stronger contrast.

## ⚙️ Running mechanism <a href="#how-it-works" id="how-it-works"></a>

When the block runs, it analyzes the input image histogram to find low and high cut points according to the selected `Threshold` value. It then rescales pixel values so the useful tonal range fills the available output range. The result is a visually brighter and higher-contrast image while trying to preserve details within the clipped range.

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

* Automatic histogram clipping to expand usable tonal range.
* Single-slider control for fast, intuitive adjustments.
* Works with grayscale and color images.
* Fast operation suitable for real-time preview and batch processing.

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

1. Connect an image source to the `Image Any` input (for example `Camera USB`, `Camera IP (ONVIF)`, `Load Image`).
2. Adjust the `Threshold` slider to control how aggressively the histogram is clipped.
3. Use the block output `Image Any` as input to visualization or further processing blocks (for example `Show Image`, `Image Logger`, `Image Write`).

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

* Combine with `Denoising` or `Blur` before contrast enhancement to reduce noise amplification on very noisy images.
* Use `Normalize Image` if you need a different normalization strategy or want to match contrast to a reference image.
* After auto contrast, fine-tune results with `Contrast-Brightness-Gamma` for more precise control over midtones and gamma.
* Preview results with `Show Image` during tuning, and save preferred results with `Image Write` or `Image Logger`.
* When working with specific color issues, try `Adjust Colors` or `Color Space` before applying auto contrast to get better color balance.

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

* Output looks too harsh or clipped: reduce the `Threshold` value to preserve more highlights/shadows.
* Loss of detail in highlights/shadows: try a lower `Threshold` or follow with `Contrast-Brightness-Gamma` adjustments.
* Increased visible noise after enhancement: apply `Denoising` before auto contrast, or reduce `Threshold`.
* Color shifts after processing: experiment with `Color Space` conversion or `Adjust Colors` before applying auto contrast.

## ✅ Best practices <a href="#best-practices" id="best-practices"></a>

* Start with a low-to-moderate `Threshold` and increase until the desired contrast is reached.
* Use `Show Image` to compare before/after in real time.
* For automated pipelines, test threshold settings on a representative set of images to avoid over/under-processing.


---

# 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/image-transformations/transformation-filters/auto-contrast.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.
