Basler recommends using the Tonal Range Auto feature first. After that, you may fine-tune the contrast by following the instructions below.
To manually adjust the contrast:
Make sure the camera already produces good images, with only issues like low contrast or shifted colors remaining. Tonal range operations should only be performed on images that already have a good image quality. When optimizing the image quality, follow the sequence given below.
Set the TonalRangeEnable parameter to On.
Set the TonalRangeSelector parameter to Sum.
Set the TonalRangeSourceDark and TonalRangeTargetDark parameters to the dark source and target values. If the dark target value is lower than the dark source value, contrast is increased.
Set the TonalRangeSourceBright and TonalRangeTargetBright parameters to the bright source and target values. If the bright target value is greater than the bright source value, contrast is increased.
Basler recommends using the Tonal Range Auto feature first. After that, you may fine-tune the color correction by following the instructions below.
To manually correct color shifts:
Make sure the camera already produces good images, with only issues like low contrast or shifted colors remaining. Tonal range operations should only be performed on images that already have a good image quality. When optimizing the image quality, follow the sequence given below.
Set the TonalRangeEnable parameter to On.
Set the TonalRangeSelector parameter to Red, Green, or Blue, depending on the color shift you want to correct. Example: If your images have a green cast, set the parameter to Green.
Set the TonalRangeSourceDark, TonalRangeTargetDark, TonalRangeSourceBright, and TonalRangeTargetBright parameters to source and target values that align the current histogram with the other histograms.
Tonal range operations are best understood by looking at a graphical representation of the tonal distribution in your images, i.e., an image histogram.
The Basler pylon Viewer provides the Histogram pane, which can be very helpful when performing tonal range operations.
Info
Depending on which other features are enabled on your camera, the Histogram pane in the pylon Viewer may not display the data that the Tonal Range feature actually uses. For example, the Gamma feature is processed after tonal range operations. As a result, gamma correction is included in the histograms displayed in the pylon Viewer, but not in the data that the Tonal Range feature uses.
As illustrated above, two sets of source and target values must be defined to perform tonal range operations:
Dark source and target values, located at the lower end of the histogram. You specify these values using the TonalRangeSourceDark and TonalRangeTargetDark parameters.
Bright source and target values, located at the upper end of the histogram. You specify these values using the TonalRangeSourceBright and TonalRangeTargetBright parameters.
All source and target values can range from 0 to the maximum pixel value (e.g., 4095 if a 12-bit pixel format is set). Because the degree of histogram stretching and spreading is limited, the parameter ranges may also be limited.
On color cameras that support the Tonal Range feature, you can also use the feature to correct color shifts.
If colors in your images are shifted, the three RGB (red, green, blue) histograms will appear unaligned. For example, if your images have a red cast, the red histogram will be displayed much further to the right than the green and blue histograms (see example below).
The Tonal Range feature allows you to manually align the RGB histograms and thus reduce color shifts.
You can align the RGB histograms by setting the source and target values so that all histograms are stretched and moved to similar starting and end points.
// Enable tonal range adjustmentscamera.TonalRangeEnable.SetValue(TonalRangeEnable_On);// Specify that the summed RGB pixel values are used for tonal range adjustmentscamera.TonalRangeSelector.SetValue(TonalRangeSelector_Sum);// Set the dark source and target valuescamera.TonalRangeSourceDark.SetValue(30);camera.TonalRangeTargetDark.SetValue(0);// Set the bright source and target valuescamera.TonalRangeSourceBright.SetValue(240);camera.TonalRangeTargetBright.SetValue(255);
INodeMap&nodemap=camera.GetNodeMap();// Enable tonal range adjustmentsCEnumParameter(nodemap,"TonalRangeEnable").SetValue("On");// Specify that the summed RGB pixel values are used for tonal range adjustmentsCEnumParameter(nodemap,"TonalRangeSelector").SetValue("Sum");// Set the dark source and target valuesCIntegerParameter(nodemap,"TonalRangeSourceDark").SetValue(30);CIntegerParameter(nodemap,"TonalRangeTargetDark").SetValue(0);// Set the bright source and target valuesCIntegerParameter(nodemap,"TonalRangeSourceBright").SetValue(240);CIntegerParameter(nodemap,"TonalRangeTargetBright").SetValue(255);
// Enable tonal range adjustmentscamera.Parameters[PLCamera.TonalRangeEnable].SetValue(PLCamera.TonalRangeEnable.On);// Specify that the summed RGB pixel values are used for tonal range adjustmentscamera.Parameters[PLCamera.TonalRangeSelector].SetValue(PLCamera.TonalRangeSelector.Sum);// Set the dark source and target valuescamera.Parameters[PLCamera.TonalRangeSourceDark].SetValue(30);camera.Parameters[PLCamera.TonalRangeTargetDark].SetValue(0);// Set the bright source and target valuescamera.Parameters[PLCamera.TonalRangeSourceBright].SetValue(240);camera.Parameters[PLCamera.TonalRangeTargetBright].SetValue(255);
/* Macro to check for errors */#define CHECK(errc) if (GENAPI_E_OK != errc) printErrorAndExit(errc)GENAPIC_RESULTerrRes=GENAPI_E_OK;/* Return value of pylon methods *//* Enable tonal range adjustments */errRes=PylonDeviceFeatureFromString(hdev,"TonalRangeEnable","On");CHECK(errRes);/* Specify that the summed RGB pixel values are used for tonal range adjustments */errRes=PylonDeviceFeatureFromString(hdev,"TonalRangeSelector","Sum");CHECK(errRes);/* Set the dark source and target values */errRes=PylonDeviceSetIntegerFeature(hdev,"TonalRangeSourceDark",30);CHECK(errRes);errRes=PylonDeviceSetIntegerFeature(hdev,"TonalRangeTargetDark",0);CHECK(errRes);/* Set the bright source and target values */errRes=PylonDeviceSetIntegerFeature(hdev,"TonalRangeSourceBright",240);CHECK(errRes);errRes=PylonDeviceSetIntegerFeature(hdev,"TonalRangeTargetBright",255);CHECK(errRes);
# Enable tonal range adjustmentscamera.TonalRangeEnable.Value="On"# Specify that the summed RGB pixel values are used for tonal range adjustmentscamera.TonalRangeSelector.Value="Sum"# Set the dark source and target valuescamera.TonalRangeSourceDark.Value=30camera.TonalRangeTargetDark.Value=0# Set the bright source and target valuescamera.TonalRangeSourceBright.Value=240camera.TonalRangeTargetBright.Value=255