> 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/image-transformations/transformation-filters/contrast-optimization.md).

# Contrast Optimization

This function block enhances local contrast of images using a contrast-limited adaptive histogram equalization technique. It is useful when details are hidden in regions with similar brightness and you want to make those details more visible without over-amplifying noise.

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

`Image Any` The input image to be contrast-enhanced. Works with color or grayscale images.

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

`Image Any` The contrast-enhanced output image.

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

`Grid Size` Adjusts the size of the local grid used for contrast equalization. Larger values create larger tiles and coarser local contrast adjustments.

`Clip Limit` Controls how strongly contrast is limited to avoid over-amplifying noise. Higher values increase the amount of contrast enhancement.

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

* Enhances local details in shadows and highlights while preventing strong noise amplification.
* Works on color images by applying enhancement to the lightness channel and preserving color.
* Interactive sliders let you tune the block in real time for your scene.

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

1. Connect an image source into `Image Any`.
2. Adjust the `Grid Size` to control the scale of local contrast patches.
3. Adjust the `Clip Limit` to control the strength of enhancement.
4. Observe the result from the `Image Any` output and fine-tune sliders as needed.

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

When executed, this function block processes the incoming image and produces an enhanced image that reveals local contrast differences while keeping noise under control.

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

* For very large images, use `Image Resizer` to reduce input size before running this block for faster processing.
* If the result looks noisy, try `Denoising` before applying this block, then compare with the original.
* To preview results while building your flow, connect the output to `Show Image`.
* If you only need a specific area enhanced, crop first with `Image ROI` and then apply this block.
* Combine with `Auto Contrast` or `Normalize Image` to compare global vs local contrast enhancement and choose the best result for your application.
* Save final images using `Image Write` or record multiple results with `Image Logger`.

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

* If images look oversaturated or noisy, reduce the `Clip Limit` or preprocess with `Denoising`.
* If very small details disappear, increase the `Grid Size` to avoid overly local adjustments.
* If processing is slow, reduce image size with `Image Resizer` before feeding into this block.
