跳转到内容

Tonal Range Auto#

相机的 Tonal Range Auto 功能使您可以一步调整对比度和/或色彩偏移。

如果您在光学显微镜上使用相机,则此功能特别有用。

如果要手动调整对比度或色彩偏移,请使用 Tonal Range 功能。

如果要使用线性或 S 曲线函数调整对比度,请使用 Brightness and Contrast 功能(如果可用)。

您可以定义多个 Auto Function ROI,这些 ROI 允许您使用图像不同部分的像素数据。

该功能的使用#

使用 Tonal Range Auto#

使用 Tonal Range Auto 的默认设置#

自动功能的参数预设为在大多数情况下都能产生良好结果的值。

要使用默认设置调整对比度和/或颜色,请执行以下操作:

  1. 确保相机已生成出色的图像,并且仅存在对比度低色彩偏移等问题。色调范围操作只能在已经具有良好图像质量的图像上执行。
    优化图像质量时,请按照以下提供的顺序操作。
  2. 至少一个自动功能 ROI 分配给 Tonal Range Auto 自动功能。
    确保自动功能 ROI 部分或完全与图像 ROI 重叠。
  3. 如果您使用的是彩色相机:
    1. If you want to adjust contrast and color in a single step, set the AutoTonalRangeModeSelector parameter to ColorAndContrast.
    2. If you only want to adjust the contrast, set the AutoTonalRangeModeSelector parameter to Contrast.
    3. 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.)
  4. 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.
  5. 如果您想进行微调,请使用 Tonal Range 功能。

使用 Tonal Range Auto 的自定义设置#

要使用自定义设置调整对比度和/或颜色,请执行以下操作:

  1. 如果您使用的是彩色相机:
    1. If you want to adjust contrast and color in a single step, set the AutoTonalRangeModeSelector parameter to ColorAndContrast.
    2. If you only want to adjust the contrast, set the AutoTonalRangeModeSelector parameter to Contrast.
    3. 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.)
  2. 设置 AutoTonalRangeAdjustmentSelector 参数设置为以下值:
    • 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.
  3. Specify the dark threshold value using the AutoTonalRangeThresholdDark parameter.
  4. Specify the bright threshold value using the AutoTonalRangeThresholdBright parameter.
  5. If the AutoTonalRangeModeSelector parameter is set to ColorAndContrast or Contrast:

    1. Set the AutoTonalRangeTargetDark parameter to the dark target value.
    2. Set the AutoTonalRangeTargetBright parameter to the bright target value.
    3. 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.
    4. 如果您想进行微调,请使用 Tonal Range 功能。

图像优化顺序#

如果要优化图像质量,请按照以下顺序操作,以避免产生副作用:

  1. 使用 Exposure TimeBlack LevelGain 功能执行基本图像优化。确保图像不会过度饱和。
  2. 如果您使用的是彩色相机,请使用 Light Source PresetBalance White AutoBalance White 功能。
  3. 使用 Tonal Range Auto 和 Tonal Range 功能优化对比度和/或颜色。

运作原理#

通过查看图像中色调分布的图形化表示(即图像直方图),可以更好地理解色调范围操作。

Basler pylon Viewer 提供了直方图窗格,这在执行色调范围操作时会非常有用。

信息

根据相机上启用的其他功能,pylon Viewer 中的直方图窗格可能不会显示自动功能实际使用的数据
例如,Gamma 功能是在色调范围操作后处理的。因此,Gamma 校正包含在 pylon Viewer 中显示的直方图中,但不包含在自动功能使用的数据中。

源和目标值#

Tonal Range Auto 功能基于与 Tonal Range 功能相同的概念:值到目标值的映射

区别在于相机确定源值和目标值的方式:

  • 相机通过计算阈值确定暗/亮值。
  • 相机如下确定暗/亮目标值

    • For contrast adjustments, the camera reads the value of the AutoTonalRangeTargetDark and AutoTonalRangeTargetBright parameters.
    • 对于色彩调节,相机会自动确定将正确对齐 RGB 直方图的目标值。

相机确定了源值和目标值后,将完全按照“Tonal Range”主题中的说明执行对比度和色彩调节。

阈值#

在自动调节色调范围时,将根据阈值自动计算源值。

You must specify the threshold values using the AutoTonalRangeThresholdDark and AutoTonalRangeThresholdBright parameters. The parameters are expressed as percentages of all pixels in your image.

信息

在本节中,假定分配的自动功能 ROI图像 ROI 相同,这是默认设置。如果您更改了自动功能 ROI 设置,则百分比是指分配的自动功能 ROI 与图像 ROI 间重叠区域中的像素。

相机根据这些百分比计算出以下内容:

  • 阈值是直方图中指定数量像素的像素值小于或等于阈值的值。
  • 阈值,是直方图中指定数量像素的像素值大于或等于阈值的值。

两个阈值之间的区域定义了中间色调,即您认为对图像至关重要的像素值。

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 only
camera.AutoTonalRangeModeSelector.SetValue(AutoTonalRangeModeSelector_Contrast);
// Specify that both ends of the tonal range are to be adjusted automatically
camera.AutoTonalRangeAdjustmentSelector.SetValue(AutoTonalRangeAdjustmentSelector_BrightAndDark);
// Set the percentage of pixels that is used to calculate the dark threshold
camera.AutoTonalRangeThresholdDark.SetValue(0.3);
// Set the percentage of pixels that is used to calculate the bright threshold
camera.AutoTonalRangeThresholdBright.SetValue(0.4);
// Set the dark target value
camera.AutoTonalRangeTargetDark.SetValue(0);
// Set the bright target value
camera.AutoTonalRangeTargetBright.SetValue(255);
// Enable the Tonal Range Auto auto function
camera.TonalRangeAuto.SetValue(TonalRangeAuto_Once);
INodeMap& nodemap = camera.GetNodeMap();
// Enable contrast adjustments only
CEnumParameter(nodemap, "AutoTonalRangeModeSelector").SetValue("Contrast");
// Specify that both ends of the tonal range are to be adjusted automatically
CEnumParameter(nodemap, "AutoTonalRangeAdjustmentSelector").SetValue("BrightAndDark");
// Set the percentage of pixels that is used to calculate the dark threshold
CFloatParameter(nodemap, "AutoTonalRangeThresholdDark").SetValue(0.3);
// Set the percentage of pixels that is used to calculate the bright threshold
CFloatParameter(nodemap, "AutoTonalRangeThresholdBright").SetValue(0.4);
// Set the dark target value
CIntegerParameter(nodemap, "AutoTonalRangeTargetDark").SetValue(0);
// Set the bright target value
CIntegerParameter(nodemap, "AutoTonalRangeTargetBright").SetValue(255);
// Enable the Tonal Range Auto auto function
CEnumParameter(nodemap, "TonalRangeAuto").SetValue("Once");
// Enable contrast adjustments only
camera.Parameters[PLCamera.AutoTonalRangeModeSelector].SetValue(PLCamera.AutoTonalRangeModeSelector.Contrast);
// Specify that both ends of the tonal range are to be adjusted automatically
camera.Parameters[PLCamera.AutoTonalRangeAdjustmentSelector].SetValue(PLCamera.AutoTonalRangeAdjustmentSelector.BrightAndDark);
// Set the percentage of pixels that is used to calculate the dark threshold
camera.Parameters[PLCamera.AutoTonalRangeThresholdDark].SetValue(0.3);
// Set the percentage of pixels that is used to calculate the bright threshold
camera.Parameters[PLCamera.AutoTonalRangeThresholdBright].SetValue(0.4);
// Set the dark target value
camera.Parameters[PLCamera.AutoTonalRangeTargetDark].SetValue(0);
// Set the bright target value
camera.Parameters[PLCamera.AutoTonalRangeTargetBright].SetValue(255);
// Enable the Tonal Range Auto auto function
camera.Parameters[PLCamera.TonalRangeAuto].SetValue(PLCamera.TonalRangeAuto.Once);
/* 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 */
/* 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 only
camera.AutoTonalRangeModeSelector.Value = "Contrast"
# Specify that both ends of the tonal range are to be adjusted automatically
camera.AutoTonalRangeAdjustmentSelector.Value = "BrightAndDark"
# Set the percentage of pixels that is used to calculate the dark threshold
camera.AutoTonalRangeThresholdDark.Value = 0.3
# Set the percentage of pixels that is used to calculate the bright threshold
camera.AutoTonalRangeThresholdBright.Value = 0.4
# Set the dark target value
camera.AutoTonalRangeTargetDark.Value = 0
# Set the bright target value
camera.AutoTonalRangeTargetBright.Value = 255
# Enable the Tonal Range Auto auto function
camera.TonalRangeAuto.Value = "Once"

您也可以使用 pylon Viewer 轻松设置参数。