<a id="easyimage-intensity-transformation"></a>

# Intensity Transformation

These EasyImage functions change the gray-levels of pixels to increase contrast.

<a id="easyimage-intensity-transformation-gain-offset"></a>

## Gain Offset

* [`EasyImage::GainOffset`](../../../doxygen_cpp/classeVision_1_1EasyImage.html#a198f67f6fe8e5e91bbda471ab5d439ca) [<sub>.NET</sub>](../../../doxygen_cs/classeVision_1_1EasyImage.html#a21914a5d707531e6a1897f1f8534216e) [<sub>Python</sub>](../../../doxygen_python/classeVision_1_1EasyImage.html#a29abc49676a17381b1c40dbbd01ac463) changes each pixel to $oldGrayValue \times GainCoefficient + Offset$.
  * **gain** adjusts **contrast**. It should remain close to 1.
  * **offset** adjusts **intensity** (brightness). It can be positive or negative.
  * The resulting values are always saturated to range $[0..255]$.
* In this example, the resulting image has better contrast and is brighter than the source image.

![](assets/images/easyimage/intensity_transformation_4a.webp)![](assets/images/easyimage/intensity_transformation_4b.webp)
* Color images have three separate gain and offset values, one per color component (red, green, blue).

![](assets/images/easyimage/intensity_transformation_5a.webp)![](assets/images/easyimage/intensity_transformation_5b.webp)

<a id="easyimage-intensity-transformation-normalization"></a>

## Normalization

[`EasyImage::Normalize`](../../../doxygen_cpp/classeVision_1_1EasyImage.html#a88610824c56e08ae9ade0f57151c2d60) [<sub>.NET</sub>](../../../doxygen_cs/classeVision_1_1EasyImage.html#acc357d7eef11747e9dc5ad58d158e9ba) [<sub>Python</sub>](../../../doxygen_python/classeVision_1_1EasyImage.html#ab7f2ec6a0583dadaeeab0bacdc51af76) makes images of the same scene comparable, even with different lighting. Images are modified so that their pixel standard deviation and average match an imposed one. This is effectively a cheap way of fixing the brightness and contrast. This operation assumes that the camera response is reasonably linear and the image does not saturate.

This method implies knowing the desired imposed pixel standard deviation and average.

* Which can be known beforehand.
* Which can be computed using [`EImageStatisticsBW8`](../../../doxygen_cpp/classeVision_1_1EImageStatisticsBW8.html) [<sub>.NET</sub>](../../../doxygen_cs/classeVision_1_1EImageStatisticsBW8.html) [<sub>Python</sub>](../../../doxygen_python/classeVision_1_1EImageStatisticsBW8.html).
  * More precisely, [`EImageStatisticsBW8::GetPixelStdDev()`](../../../doxygen_cpp/classeVision_1_1EImageStatisticsBW8.html#a7a7128da45dbc7c1064bfcedd6c25fcd) [<sub>.NET</sub>](../../../doxygen_cs/classeVision_1_1EImageStatisticsBW8.html#ac7565056a7164eaffc8690b93f31f868) [<sub>Python</sub>](../../../doxygen_python/classeVision_1_1EImageStatisticsBW8.html#af8070e7a9e5e0a5a5454764aa8311054) and [`EImageStatisticsBW8::GetPixelAverage()`](../../../doxygen_cpp/classeVision_1_1EImageStatisticsBW8.html#aad93fe63e7fd6096da43e17faaefe188) [<sub>.NET</sub>](../../../doxygen_cs/classeVision_1_1EImageStatisticsBW8.html#a9d8a0682304650af42717e3f4ae305d1) [<sub>Python</sub>](../../../doxygen_python/classeVision_1_1EImageStatisticsBW8.html#a19ad9b2181a33cc50cd2af32367d30e2)

![](assets/images/easyimage/intensity_transformation_4a.webp)![](assets/images/easyimage/intensity_transformation_4b.webp)![](assets/images/easyimage/intensity_transformation_1b_destination.webp)

<a id="easyimage-intensity-transformation-uniformization"></a>

## Uniformization

* [`EasyImage::Uniformize`](../../../doxygen_cpp/classeVision_1_1EasyImage.html#aef9f48bee1072dd6a8285b1db4c0c248) [<sub>.NET</sub>](../../../doxygen_cs/classeVision_1_1EasyImage.html#a274bb15f6d67ab0aeb0dceaf4cf4aca4) [<sub>Python</sub>](../../../doxygen_python/classeVision_1_1EasyImage.html#ac7abbe991c912299ae1ff91133be5c83) compensates for non-uniform illumination and/or camera sensitivity based on one or two reference images. The reference image should not contain saturated pixel values and have minimum noise.
  * When one reference image is used, the transformation is similar to an adaptive (space-variant) gain; each pixel in the reference image encodes the gain for the corresponding pixel in the source image.
* When two reference images are used, the transformation is similar to an adaptive gain and offset; each pixel in the reference images encodes either the gain or the offset for the corresponding pixel in the source image.

![](assets/images/easyimage/uniformization_light_reference.webp)![](assets/images/easyimage/uniformization_dark_reference.webp)![](assets/images/easyimage/uniformization_source.webp)![](assets/images/easyimage/uniformization_output.webp)

<a id="easyimage-intensity-transformation-lut"></a>

## Lookup Tables

[`EasyImage::Lut`](../../../doxygen_cpp/classeVision_1_1EasyImage.html#a9760d9a0411555f716fbae96a2b7034a) [<sub>.NET</sub>](../../../doxygen_cs/classeVision_1_1EasyImage.html#a3a3e2d078ad4178f9e44784ef6a5a947) [<sub>Python</sub>](../../../doxygen_python/classeVision_1_1EasyImage.html#aa2fee63b3dac911748263c3915b0abf6) uses a lookup table of new pixel values to replace the current ones. This method should be used when the transform function never changes. This operation is usually faster than other transformative operation. When using [`EasyImage::Lut`](../../../doxygen_cpp/classeVision_1_1EasyImage.html#a9760d9a0411555f716fbae96a2b7034a) [<sub>.NET</sub>](../../../doxygen_cs/classeVision_1_1EasyImage.html#a3a3e2d078ad4178f9e44784ef6a5a947) [<sub>Python</sub>](../../../doxygen_python/classeVision_1_1EasyImage.html#aa2fee63b3dac911748263c3915b0abf6), the lookup table should be initialized before.

Here is an example of the usage of a lookup to apply a simple tone-mapper designed to increase contrast and slightly reduce the brightness.

![](assets/images/easyimage/intensity_transformation_4b.webp)![](assets/images/easyimage/correctedImage_with_lookup.webp)![](assets/images/easyimage/graph_lookup_table.png)

<a id="easyimage-intensity-transformation-quick-links"></a>

## See Also

Easy to understand, ready to copy code snippets.

Conceptual guide to choosing and applying spatial and temporal noise reduction.

Frequency-selective convolution for texture analysis using the Gabor wavelet.
