# Contrast Optimization

This function block utilizes the CLAHE (Contrast Limited Adaptive Histogram Equalization) algorithm to enhance image contrast. It is particularly effective for improving the visibility of bright regions in images with varied lighting conditions.

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

`Image Any` A single image to be processed and enhanced using the CLAHE technique.

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

`Image Any` The output is the enhanced version of the input image after applying the CLAHE algorithm.

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

`Grid Size` A slider to adjust the size of the grid used by the CLAHE algorithm. Increasing the size can enhance contrast in larger areas of the image.

`Clip Limit` A slider to set the clip limit for the CLAHE algorithm. This value controls the contrast amplification; higher values allow greater amplification of contrast.

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

`Real-time Adjustment` The grid size and clip limit can be adjusted dynamically, allowing users to fine-tune the enhancement effect on the fly.

`Adaptive Contrast Enhancement` The CLAHE algorithm improves contrast more effectively in images with close brightness regions, enhancing visibility without over-saturating the image.

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

1. **Input Image**: Connect any image to the input socket.
2. **Adjust Parameters**: Use the `Grid Size` and `Clip Limit` sliders to set your desired enhancement parameters.
3. **Evaluate**: Run the block to apply the CLAHE algorithm and view the resulting enhanced image.

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

On execution, this function block applies the CLAHE algorithm to the input image, returning the enhanced image with improved contrast.

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

<details>

<summary>Grid Size Adjustment</summary>

Smaller grid sizes will adapt to localized areas of the image better, while larger sizes will apply more global enhancements. Experiment with different sizes for optimal results.

</details>

<details>

<summary>Clip Limit Settings</summary>

A higher clip limit can produce a greater contrast effect but may also result in noise. Fine-tune it to find a balance for the specific image you are processing.

</details>

<details>

<summary>Preprocessing Images</summary>

For best results, preprocess your image using a `Denoising` function block to remove noise before applying the Contrast Optimization.

</details>

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

<details>

<summary>No Changes on Output</summary>

Ensure that your input image is correctly connected and the values on the sliders are within their valid ranges (Grid Size: 2-20, Clip Limit: 2-100).

</details>

<details>

<summary>Artifacts in Enhanced Image</summary>

If you notice artifacts after applying CLAHE, consider reducing the clip limit as high values may lead to over-enhancement and visual distortions.

</details>
