AutoLevels automatically adjusts brightness and contrast to produce a balanced image with a good range of color intensities. In doing so it performs a function very much like the Levels effect, automatically deriving settings based on the image provided.

Well defined images span an entire range of color intensities. However it is common to find images that do not. If a photo has been overexposed it will be too bright - there will be few colors at the low ends of intensity and many at the high end. Similarly if a photograph has been underexposed it will be very dark - all the colors will be at the low end of the range and virtually none at the high end.

The AutoLevels effect detects and fixes this kind of imbalance. It scans through the levels of intensity within the image and chooses a level that should be regarded as black (low intensity) and another that should be regarded as white (high intensity). It then stretches the levels in the image so that all the intensities present lie between the black and the white points. This results in an image with a good span of color intensities.

To mitigate the effect of outliers - small numbers of pixels at extreme values of intensity - a clipping percentage is used. By default the value is 0.5% which means that the bottom and top 0.5% of pixels will be ignored when determining the black and white points.

Syntax

[C#]

static void AutoLevels(Bitmap bitmap, Nullable<double> clip);

[Visual Basic]

Shared Sub AutoLevels(bitmap As Bitmap, clip As Nullable(Of Double))
Params
Name Description
bitmap The bitmap to process
clip The percentage of extreme color values to ignore. This applies to the top and the bottom extremes. If null is provided this defaults to 0.5%.
Notes

None.

Example

[C#]

using (Bitmap bm = (Bitmap)Bitmap.FromFile(Server.MapPath("rez/pietro-de-grandi-6U4wogjLArk-unsplash.jpg"))) {
  Effects.AutoLevels(bm, null);
  bm.Save(Server.MapPath("IG8_Effects_AutoLevels1.jpg"));
}
using (Bitmap bm = (Bitmap)Bitmap.FromFile(Server.MapPath("rez/pietro-de-grandi-6U4wogjLArk-unsplash.jpg"))) {
  Effects.AutoLevels(bm, 5);
  bm.Save(Server.MapPath("IG8_Effects_AutoLevels2.jpg"));
}


Here we apply an auto-levels effect with different clip levels. Ouput files are shown below.


pietro-de-grandi-6U4wogjLArk-unsplash.jpg


IG8_Effects_AutoLevels1.jpg


IG8_Effects_AutoLevels2.jpg