Skip to content

Brightness and Contrast#

The Brightness and Contrast camera feature allows you to adjust the tonal values of your images.

Brightness and contrast are always processed together as parts of a common mathematical Brightness/Contrast function.

Using the Feature#

Adjusting Contrast and Contrast Mode#

To adjust the contrast:

  1. Set the BslContrastMode parameter to one of the following values:
  2. Enter a value for the BslContrast parameter. The parameter's value range is from -1 to 1. By default, the parameter is set to 0 which means that the contrast remains unchanged.

Adjusting Brightness#

To adjust the brightness, enter a value for the BslBrightness parameter. The parameter's value range is from -1 to 1. By default, the parameter is set to 0 which means that the brightness remains unchanged.

How It Works#

Contrast and Contrast Modes#

Adjusting the contrast changes the degree of difference between light and dark areas in the image. The more contrast you apply, the more pronounced the difference will be.

How the contrast is applied depends on the contrast mode that you select.

Linear Contrast Mode

This is the default contrast mode. If this contrast mode is selected, the camera uses a linear function to adjust the contrast. Increasing or decreasing the contrast, increases or decreases the gradient of the linear function.

Contrast = 0, Brightness = 0, Linear Contrast Mode

Contrast = 0.3, Brightness = 0, Linear Contrast Mode

With a contrast setting greater than 0, more output pixel values will be set to completely black (0) or completely white (maximum pixel value).

If the contrast is set to 0.3 (see second figure), input values from 0 to approximately 50 are set to completely black, and input values from approximately 205 to 255 are set to completely white. This means that the overall range of tonal values, i.e, the dynamic range of the image, is reduced. The darkest and lightest regions of the image will appear completely black or completely white, but the other areas will appear more defined.

Decreasing the contrast has the opposite effect.

S-Curve Contrast Mode

If this contrast mode is selected, the camera uses an S-curve function to adjust the contrast.

This allows you to improve the perceived contrast while preserving the dynamic range of the image.

The more you increase the contrast, the more S-shaped the graph of the function will be:

Contrast = 0.3, Brightness = 0, S-Curve Contrast Mode

Contrast = 0.5, Brightness = 0, S-Curve Contrast Mode

The figures above show that increasing the contrast in S-Curve mode has the following effects:

  • The S-curve gets flatter around its starting and end points and steeper around the center. As a result, contrast in light and dark areas of the image is reduced, and contrast in mid tones is increased.
  • Low input pixel values are lowered and high input pixel values are increased. As a result, extreme dark and light areas of your image are compressed, which further improves the perceived contrast.
  • As the curve always starts at (0,0) and ends at (Xmax,Ymax), the dynamic range of the image is preserved.

Contrast settings below 0 in S-Curve mode will result in an inverted S-curve with opposite effects.

Brightness#

Adjusting the brightness allows you to lighten or darken the image by increasing or decreasing its tonal values.

Adjusting the brightness moves the pivot point of the Brightness/Contrast function:

  • Increasing the brightness moves the pivot point towards the upper left. This means that the image will appear lighter.
  • Decreasing the brightness moves the pivot point to the lower right. This means that the image will appear darker.

The figures below show examples with the S-Curve contrast mode selected.

Contrast = 0.3, Brightness = 0, S-Curve Contrast Mode

Contrast = 0.3, Brightness = 0.3, S-Curve Contrast Mode

Additional Parameters#

If available, the BslBrightnessRaw and BslContrastRaw parameters allow you to enter integer values instead of float values for the brightness and contrast parameters. Normally, you don't need to set these parameters.

Sample Code#

// Set the Brightness parameter to 0.5
camera.BslBrightness.SetValue(0.5);
// Set the contrast mode to Linear
camera.BslContrastMode.SetValue(BslContrastMode_Linear);
// Set the Contrast parameter to 1.2
camera.BslContrast.SetValue(1.2);
INodeMap& nodemap = camera.GetNodeMap();
// Set the Brightness parameter to 0.5
CFloatPtr(nodemap.GetNode("BslBrightness"))->SetValue(0.5);
// Set the contrast mode to Linear
CEnumerationPtr(nodemap.GetNode("BslContrastMode"))->FromString("Linear");
// Set the Contrast parameter to 1.2
CFloatPtr(nodemap.GetNode("BslContrast"))->SetValue(1.2);
INodeMap& nodemap = camera.GetNodeMap();
// Set the Brightness parameter to 0.5
CFloatParameter(nodemap, "BslBrightness").SetValue(0.5);
// Set the contrast mode to Linear
CEnumParameter(nodemap, "BslContrastMode").SetValue("Linear");
// Set the Contrast parameter to 1.2
CFloatParameter(nodemap, "BslContrast").SetValue(1.2);
// Set the Brightness parameter to 0.5
camera.Parameters[PLCamera.BslBrightness].SetValue(0.5);
// Set the contrast mode to Linear
camera.Parameters[PLCamera.BslContrastMode].SetValue(PLCamera.BslContrastMode.Linear);
// Set the Contrast parameter to 1.2
camera.Parameters[PLCamera.BslContrast].SetValue(1.2);
// Set the Brightness parameter to 0.5
Pylon.DeviceSetFloatFeature(hdev, "BslBrightness", 0.5);
// Set the contrast mode to Linear
Pylon.DeviceFeatureFromString(hdev, "BslContrastMode", "Linear");
// Set the Contrast parameter to 1.2
Pylon.DeviceSetFloatFeature(hdev, "BslContrast", 1.2);
/* Macro to check for errors */
#define CHECK(errc) if (GENAPI_E_OK != errc) printErrorAndExit(errc)
GENAPIC_RESULT errRes = GENAPI_E_OK;  /* Return value of pylon methods */
/* Set the Brightness parameter to 0.5 */
errRes = PylonDeviceSetFloatFeature(hdev, "BslBrightness", 0.5);
CHECK(errRes);
/* Set the contrast mode to Linear */
errRes = PylonDeviceFeatureFromString(hdev, "BslContrastMode", "Linear");
CHECK(errRes);
/* Set the Contrast parameter to 1.2 */
errRes = PylonDeviceSetFloatFeature(hdev, "BslContrast", 1.2);
CHECK(errRes);

You can also use the pylon Viewer to easily set the parameters.