The parameters of the auto function are preset to values that deliver good results in most scenarios.
To adjust the contrast or color or both using the default settings:
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.
Assign at least one auto function ROI to the Tonal Range Auto auto function. Make sure the auto function ROI overlaps the image ROI, either partially or completely.
If you are using a color camera:
If you want to adjust contrast and color in a single step, set the AutoTonalRangeModeSelector parameter to ColorAndContrast.
If you only want to adjust the contrast, set the AutoTonalRangeModeSelector parameter to Contrast.
If you only want to correct color shifts, set the AutoTonalRangeModeSelector parameter to Color. (If you are using a mono camera, only contrast adjustment is available. The AutoTonalRangeModeSelector parameter is preset to Contrast and can't be changed.)
Set the TonalRangeAuto parameter to Once. With the next image acquisition, the camera adjusts contrast or color or both using the default settings. When the adjustment is complete, the camera sets the auto function to Off and applies the adjustment to all subsequent images.
If you want to fine-tune the adjustments, use the Tonal Range feature.
To adjust the contrast or color or both using custom settings:
If you are using a color camera:
If you want to adjust contrast and color in a single step, set the AutoTonalRangeModeSelector parameter to ColorAndContrast.
If you only want to adjust the contrast, set the AutoTonalRangeModeSelector parameter to Contrast.
If you only want to correct color shifts, set the AutoTonalRangeModeSelector parameter to Color. (If you are using a mono camera, only contrast adjustment is available. The AutoTonalRangeModeSelector parameter is preset to Contrast and can't be changed.)
Set the AutoTonalRangeAdjustmentSelector parameter to one of the following values:
BrightAndDark (default): Automatic adjustments are applied to dark and bright parts of your images.
Dark: Automatic adjustments are applied to dark parts of your images only.
Bright: Automatic adjustments are applied to bright parts of your images only.
Specify the dark threshold value using the AutoTonalRangeThresholdDark parameter.
Specify the bright threshold value using the AutoTonalRangeThresholdBright parameter.
If the AutoTonalRangeModeSelector parameter is set to ColorAndContrast or Contrast:
Set the AutoTonalRangeTargetDark parameter to the dark target value.
Set the AutoTonalRangeTargetBright parameter to the bright target value.
Set the TonalRangeAuto parameter to Once. With the next image acquisition, the camera adjusts contrast or color or both using the default settings. When the adjustment is complete, the camera sets the auto function to Off and applies the adjustment to all subsequent simages.
If you want to fine-tune the adjustments, use the Tonal Range feature.
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 auto function 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 auto function uses.
What's different is how the camera determines the source and target values:
The camera determines the dark and bright source values by calculating the threshold values.
The camera determines the dark and bright target values as follows:
For contrast adjustments, the camera reads the value of the AutoTonalRangeTargetDark and AutoTonalRangeTargetBright parameters.
For color adjustments, the camera automatically determines target values that will properly align the RGB histograms.
Once the camera has determined the source and target values, the camera performs contrast and color adjustments exactly as described in the Tonal Range topic.
During automatic tonal range adjustments, the source values are calculated automatically based on threshold values.
You must specify the threshold values using the AutoTonalRangeThresholdDark and AutoTonalRangeThresholdBright parameters. The parameters are expressed as percentages of all pixels in your image.
Info
In this section, it is assumed that the assigned auto function ROI and the image ROI are identical, which is the default setting. if you changed your auto function ROI settings, the percentages refer to the pixels in the areas of overlap between the assigned auto function ROI and the image ROI.
From the percentages, the camera calculates the following:
The dark threshold value, which is the value in the histogram where the specified amount of pixels have a pixel value lower than or equal to the threshold value.
The bright threshold value, which is the value in the histogram where the specified amount of pixels have a pixel value greater than or equal to the threshold value.
The area between both thresholds defines your mid-tones, i.e., the pixel values you consider essential for the image.
Example: Assume you set the AutoTonalRangeThresholdDark parameter to 0.3 and the AutoTonalRangeThresholdBright parameter to 0.4. The camera detects that 0.3 % of the pixels in your image have a pixel value lower than or equal to 52, and 0.4 % of the pixels in your image have a pixel value greater than or equal to 204. Therefore, the dark threshold value is 52, and the bright threshold value is 204.
// Enable contrast adjustments onlycamera.AutoTonalRangeModeSelector.SetValue(AutoTonalRangeModeSelector_Contrast);// Specify that both ends of the tonal range are to be adjusted automaticallycamera.AutoTonalRangeAdjustmentSelector.SetValue(AutoTonalRangeAdjustmentSelector_BrightAndDark);// Set the percentage of pixels that is used to calculate the dark thresholdcamera.AutoTonalRangeThresholdDark.SetValue(0.3);// Set the percentage of pixels that is used to calculate the bright thresholdcamera.AutoTonalRangeThresholdBright.SetValue(0.4);// Set the dark target valuecamera.AutoTonalRangeTargetDark.SetValue(0);// Set the bright target valuecamera.AutoTonalRangeTargetBright.SetValue(255);// Enable the Tonal Range Auto auto functioncamera.TonalRangeAuto.SetValue(TonalRangeAuto_Once);
INodeMap&nodemap=camera.GetNodeMap();// Enable contrast adjustments onlyCEnumParameter(nodemap,"AutoTonalRangeModeSelector").SetValue("Contrast");// Specify that both ends of the tonal range are to be adjusted automaticallyCEnumParameter(nodemap,"AutoTonalRangeAdjustmentSelector").SetValue("BrightAndDark");// Set the percentage of pixels that is used to calculate the dark thresholdCFloatParameter(nodemap,"AutoTonalRangeThresholdDark").SetValue(0.3);// Set the percentage of pixels that is used to calculate the bright thresholdCFloatParameter(nodemap,"AutoTonalRangeThresholdBright").SetValue(0.4);// Set the dark target valueCIntegerParameter(nodemap,"AutoTonalRangeTargetDark").SetValue(0);// Set the bright target valueCIntegerParameter(nodemap,"AutoTonalRangeTargetBright").SetValue(255);// Enable the Tonal Range Auto auto functionCEnumParameter(nodemap,"TonalRangeAuto").SetValue("Once");
// Enable contrast adjustments onlycamera.Parameters[PLCamera.AutoTonalRangeModeSelector].SetValue(PLCamera.AutoTonalRangeModeSelector.Contrast);// Specify that both ends of the tonal range are to be adjusted automaticallycamera.Parameters[PLCamera.AutoTonalRangeAdjustmentSelector].SetValue(PLCamera.AutoTonalRangeAdjustmentSelector.BrightAndDark);// Set the percentage of pixels that is used to calculate the dark thresholdcamera.Parameters[PLCamera.AutoTonalRangeThresholdDark].SetValue(0.3);// Set the percentage of pixels that is used to calculate the bright thresholdcamera.Parameters[PLCamera.AutoTonalRangeThresholdBright].SetValue(0.4);// Set the dark target valuecamera.Parameters[PLCamera.AutoTonalRangeTargetDark].SetValue(0);// Set the bright target valuecamera.Parameters[PLCamera.AutoTonalRangeTargetBright].SetValue(255);// Enable the Tonal Range Auto auto functioncamera.Parameters[PLCamera.TonalRangeAuto].SetValue(PLCamera.TonalRangeAuto.Once);
/* 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 contrast adjustments only */errRes=PylonDeviceFeatureFromString(hdev,"AutoTonalRangeModeSelector","Contrast");CHECK(errRes);/* Specify that both ends of the tonal range are to be adjusted automatically */errRes=PylonDeviceFeatureFromString(hdev,"AutoTonalRangeAdjustmentSelector","BrightAndDark");CHECK(errRes);/* Set the percentage of pixels that is used to calculate the dark threshold */errRes=PylonDeviceSetFloatFeature(hdev,"AutoTonalRangeThresholdDark",0.3);CHECK(errRes);/* Set the percentage of pixels that is used to calculate the bright threshold */errRes=PylonDeviceSetFloatFeature(hdev,"AutoTonalRangeThresholdBright",0.4);CHECK(errRes);/* Set the dark target value */errRes=PylonDeviceSetIntegerFeature(hdev,"AutoTonalRangeTargetDark",0);CHECK(errRes);/* Set the bright target value */errRes=PylonDeviceSetIntegerFeature(hdev,"AutoTonalRangeTargetBright",255);CHECK(errRes);/* Enable the Tonal Range Auto auto function */errRes=PylonDeviceFeatureFromString(hdev,"TonalRangeAuto","Once");CHECK(errRes);
# Enable contrast adjustments onlycamera.AutoTonalRangeModeSelector.Value="Contrast"# Specify that both ends of the tonal range are to be adjusted automaticallycamera.AutoTonalRangeAdjustmentSelector.Value="BrightAndDark"# Set the percentage of pixels that is used to calculate the dark thresholdcamera.AutoTonalRangeThresholdDark.Value=0.3# Set the percentage of pixels that is used to calculate the bright thresholdcamera.AutoTonalRangeThresholdBright.Value=0.4# Set the dark target valuecamera.AutoTonalRangeTargetDark.Value=0# Set the bright target valuecamera.AutoTonalRangeTargetBright.Value=255# Enable the Tonal Range Auto auto functioncamera.TonalRangeAuto.Value="Once"