---
title: "Brightness and Contrast"
canonical: https://www.graphicsmill.com/docs/gm/brightness-and-contrast.htm
product: "Graphics Mill"
---

# Brightness and Contrast
 
One of the most popular bitmap tone correction tasks is the adjusting of brightness and contrast. The ability to edit brightness and contrast is available in most imaging applications. Professional photo retouchers do not like these algorithms for being too "rough", and prefer using levels and curves correction (described below), but inexperienced users tent to prefer the simplicity of brightness and contrast editing.
 
Before describing how to use brightness and contrast algorithms in Graphics Mill, let's provide some definitions.
 
## Definitions
  
*Pixel intensity* is the value which characterizes the "lightness" of the pixel. For RGB values the intensity can be interpreted as the mean value of its channels.
 
*Bitmap brightness* is the degree of pixel intensity. For brevity let's assume that we are working with a grayscale bitmap. If most pixels of this bitmap have small values (e.g. close to 0), the bitmap is called *dark*. Vice versa, if most pixels have large values (e.g. close to the maximum value - 255 for 8-bit images, and 65355 for 16-bit images), the bitmap is called *bright*.
 
*Bitmap contrast* is the degree of scattering between pixel values, and can be determined as the difference between the brightest and the darkest pixels of the bitmap. When the image has low contrast it looks faded and the details are hardly perceptible. Alternately, high-contrast images are sharp and details are easy to perceive.
 
## Brightness
  
To modify the brightness of the bitmap, the [ColorAdjustmentProvider](https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_ColorAdjustmentProvider.htm.md) provides the [Brightness(Single)](https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_ColorAdjustmentProvider_Brightness_1_7a94462e.htm.md) method (the appropriate transform class is [Brightness](https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Transforms_Brightness.htm.md)). It has a single parameter - a brightness amount. It is a float value in range [-1, 1]. If it is more than 0, the image is brightened (amount = 1 will make the image completely white). If it is less than 0, the image is darkened (amount = -1 will make the image completely black). A zero value will cause no changes.
 
Here is a code example which demonstrates how to use it:
 
```csharp
bitmap.ColorAdjustment.Brightness(0.2f);
```
 
Here is the same demonstration using the **Brightness** transform:
 
```csharp
using (var bitmap = new Bitmap(@"Images\in.jpg"))
using (var brightness = new Brightness())
{
    brightness.Auto = false;
    brightness.Amount = 0.2f;

    using (var newbitmap = brightness.Apply(bitmap))
        newbitmap.Save(@"Images\Output\out.jpg");
}
```
 
Graphics Mill can also correct brightness in automatic mode by simply using the [AutoBrightness()](https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_ColorAdjustmentProvider_AutoBrightness.htm.md) method of the **ColorAdjustmentProvider** class. Alternatively, you can set the [Auto](https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Transforms_Brightness_Auto.htm.md) property of the **Brightness** transform as `true`. The syntax is demonstrated here:
 
```csharp
bitmap.ColorAdjustment.AutoBrightness();
```
 
Here is the same task using the **Brightness** transform:
 
```csharp
using (var bitmap = new Bitmap(@"Images\in.jpg"))
using (var brightness = new Brightness())
{
    brightness.Auto = true;

    using (var newbitmap = brightness.Apply(bitmap))
        newbitmap.Save(@"Images\Output\out.jpg");
}
```
 
The [Apply(Bitmap)](https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_Transforms_Transform_Apply_1_fd4033ef.htm.md) method produces a transformed copy of a given bitmap, but the source bitmap remains unchanged. You can use the **Brightness** class to calculate the brightness amount parameter with the [CalculateAuto(Bitmap)](https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_Transforms_Brightness_CalculateAuto_1_fd4033ef.htm.md) method without applying the transform itself. This can be useful when you want to suggest some initial parameter to the user.
 
## Contrast
  
To modify the contrast you can use the [Contrast(Single)](https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_ColorAdjustmentProvider_Contrast_1_7a94462e.htm.md) method of the **ColorAdjustmentProvider** (or its analogue - [Contrast](https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Transforms_Contrast.htm.md) transform). This method is very similar to brightness: it also has a single parameter - amount, which is also a value in the range [-1, 1]. Positive values mean that the contrast should be increased (value = 1 will set the image contrast to the maximum, i.e. all pixels will have either maximum or minimum intensity, without middle values). Negative values mean that the contrast will be decreased (value = -1 will make the image completely gray, i.e. all pixels will have the same value). A zero value will cause no changes.
 
Automatic mode works in a similar way, including the automatic calculation of the most appropriate contrast amount.
 
Here you can see a code example for the contrast:
 
```csharp
bitmap.ColorAdjustment.Contrast(0.2f);
```
 
Here is the same using the **Contrast** transform:
 
```csharp
using (var bitmap = new Bitmap(@"Images\in.jpg"))
using (var contrast = new Contrast())
{
    contrast.Auto = false;
    contrast.Amount = 0.2f;

    using (var newbitmap = contrast.Apply(bitmap))
        newbitmap.Save(@"Images\Output\out.jpg");
}
```
 
Automatic mode:
 
```csharp
bitmap.ColorAdjustment.AutoContrast();
```
 
Here is the same using the **Contrast** transform:
 
```csharp
using (var bitmap = new Bitmap(@"Images\in.jpg"))
using (var contrast = new Contrast())
{
    contrast.Auto = true;

    using (var newbitmap = contrast.Apply(bitmap))
        newbitmap.Save(@"Images\Output\out.jpg");
}
```
 
## Combined Brightness and Contrast
  
Typically both brightness and contrast should be modified simultaneously. Graphics Mill provides the combined method [BrightnessContrast(Single, Single)](https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_ColorAdjustmentProvider_BrightnessContrast_2_427c5821.htm.md) (and the transform class [BrightnessContrast](https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Transforms_BrightnessContrast.htm.md)) that takes two parameters - brightness and contrast amounts. These are the same as described above.
 
We recommend that you use the combined method when both brightness and contrast should be modified, rather than the serial calls of the previous ones. It is more convenient in practice and works slightly faster.
 
The code samples for the combined brightness/contrast method are demonstrated below:
 
```csharp
bitmap.ColorAdjustment.BrightnessContrast(0.9f, 0f);
```
 
Here is the same using the **BrightnessContrast** transform:
 
```csharp
using (var bitmap = new Bitmap(@"Images\in.jpg"))
using (var brightnessContrast = new BrightnessContrast())
{
    brightnessContrast.Brightness = 0.2f;
    brightnessContrast.Contrast = 0.2f;

    using (var newbitmap = brightnessContrast.Apply(bitmap))
        newbitmap.Save(@"Images\Output\out.jpg");
}
```
 
## See Also
  
### Reference
 
- [ColorAdjustmentProvider Class](https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_ColorAdjustmentProvider.htm.md)
- [Brightness(Single) Method](https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_ColorAdjustmentProvider_Brightness_1_7a94462e.htm.md)
- [Brightness Class](https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Transforms_Brightness.htm.md)
- [AutoBrightness() Method](https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_ColorAdjustmentProvider_AutoBrightness.htm.md)
- [Auto Property](https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Transforms_Brightness_Auto.htm.md)
- [CalculateAuto(Bitmap) Method](https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_Transforms_Brightness_CalculateAuto_1_fd4033ef.htm.md)
- [Contrast(Single) Method](https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_ColorAdjustmentProvider_Contrast_1_7a94462e.htm.md)
- [Contrast Class](https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Transforms_Contrast.htm.md)
- [BrightnessContrast(Single, Single) Method](https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_ColorAdjustmentProvider_BrightnessContrast_2_427c5821.htm.md)
- [BrightnessContrast Class](https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Transforms_BrightnessContrast.htm.md)
