As this relation is non linear, the effect will not be the same for all the pixels and will depend to their original value.
![Plot for different values of gamma](images/Basic_Linear_Transform_Tutorial_gamma.png)
When \f$ \gamma <1 \f$,theoriginaldarkregionswillbebrighterandthehistogramwillbeshiftedtotherightwhereasitwill
be the opposite with \f$ \gamma > 1 \f$.
### Correct an underexposed image
The following image has been corrected with: \f$ \alpha = 1.3 \f$ and \f$ \beta = 40 \f$.
![By Visem (Own work) [CC BY-SA 3.0], via Wikimedia Commons](images/Basic_Linear_Transform_Tutorial_linear_transform_correction.jpg)
The overall brightness has been improved but you can notice that the clouds are now greatly saturated due to the numerical saturation
of the implementation used. A custom method that preserves the original color range can of course be implemented instead.
The following image has been corrected with: \f$ \gamma = 0.4 \f$.
![By Visem (Own work) [CC BY-SA 3.0], via Wikimedia Commons](images/Basic_Linear_Transform_Tutorial_gamma_correction.jpg)
The gamma correction should tend to add less saturation effect but should introduce some other type of color artifacts instead.
![Left: histogram after alpha, beta correction ; Center: histogram of the original image ; Right: histogram after the gamma correction](images/Basic_Linear_Transform_Tutorial_histogram_compare.png)
The previous figure compares the histograms for the three images (the y-ranges are not the same between the three histograms).
You can notice that most of the pixel values are in the lower part of the histogram for the original image. After \f$ \alpha \f$,
\f$ \beta \f$ correction, we can observe a big peak at 255 due to the saturation as well as a shift in the right.
After gamma correction, the histogram is shifted to the right but the pixels in the dark regions are more shifted
(see the gamma curves [figure](Basic_Linear_Transform_Tutorial_gamma.png)) than those in the bright regions.
In this tutorial, you have seen two simple methods to adjust the contrast and the brightness of an image. **They are basic techniques
and are not intended to be used as a replacement of a raster graphics editor!**
### Code
Code for the tutorial is [here](changing_contrast_brightness_image.cpp). Code for the gamma correction: