Tonal Range Auto#
如果您在光学显微镜上使用相机,则此功能特别有用。
如果要手动调整对比度或色彩偏移,请使用 Tonal Range 功能。
如果要使用线性或 S 曲线函数调整对比度,请使用 Brightness and Contrast 功能(如果可用)。
您可以定义多个 Auto Function ROI,这些 ROI 允许您使用图像不同部分的像素数据。
该功能的使用#
使用 Tonal Range Auto#
使用 Tonal Range Auto 的默认设置#
自动功能的参数预设为在大多数情况下都能产生良好结果的值。
要使用默认设置调整对比度和/或颜色,请执行以下操作:
- 确保相机已生成出色的图像,并且仅存在对比度低或色彩偏移等问题。色调范围操作只能在已经具有良好图像质量的图像上执行。
优化图像质量时,请按照以下提供的顺序操作。 - 将至少一个自动功能 ROI 分配给 Tonal Range Auto 自动功能。
确保自动功能 ROI 部分或完全与图像 ROI 重叠。 - 如果您使用的是彩色相机:
- If you want to adjust contrast and color in a single step, set the
AutoTonalRangeModeSelector
parameter toColorAndContrast
. - If you only want to adjust the contrast, set the
AutoTonalRangeModeSelector
parameter to对比度
. - If you only want to correct color shifts, set the
AutoTonalRangeModeSelector
parameter to彩色
.
(If you are using a mono camera, only contrast adjustment is available. TheAutoTonalRangeModeSelector
parameter is preset to对比度
and can't be changed.)
- If you want to adjust contrast and color in a single step, set the
- 设置
TonalRangeAuto
parameter toOnce
.
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熄灭
and applies the adjustment to all subsequent images. - 如果您想进行微调,请使用 Tonal Range 功能。
使用 Tonal Range Auto 的自定义设置#
要使用自定义设置调整对比度和/或颜色,请执行以下操作:
- 如果您使用的是彩色相机:
- If you want to adjust contrast and color in a single step, set the
AutoTonalRangeModeSelector
parameter toColorAndContrast
. - If you only want to adjust the contrast, set the
AutoTonalRangeModeSelector
parameter to对比度
. - If you only want to correct color shifts, set the
AutoTonalRangeModeSelector
parameter to彩色
.
(If you are using a mono camera, only contrast adjustment is available. TheAutoTonalRangeModeSelector
parameter is preset to对比度
and can't be changed.)
- If you want to adjust contrast and color in a single step, set the
- 设置
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.
- Specify the dark threshold value using the
AutoTonalRangeThresholdDark
parameter. - Specify the bright threshold value using the
AutoTonalRangeThresholdBright
parameter. -
If the
AutoTonalRangeModeSelector
parameter is set toColorAndContrast
或对比度
:- 设置
AutoTonalRangeTargetDark
parameter to the dark target value. - 设置
AutoTonalRangeTargetBright
parameter to the bright target value. - 设置
TonalRangeAuto
parameter toOnce
.
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熄灭
and applies the adjustment to all subsequent simages. - 如果您想进行微调,请使用 Tonal Range 功能。
- 设置
图像优化顺序#
如果要优化图像质量,请按照以下顺序操作,以避免产生副作用:
- 使用 Exposure Time、Black Level 和 Gain 功能执行基本图像优化。确保图像不会过度饱和。
- 如果您使用的是彩色相机,请使用 Light Source Preset、Balance White Auto 或 Balance White 功能。
- 使用 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
andAutoTonalRangeTargetBright
parameters. - 对于色彩调节,相机会自动确定将正确对齐 RGB 直方图的目标值。
- For contrast adjustments, the camera reads the value of the
相机确定了源值和目标值后,将完全按照“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.
相机根据这些百分比计算出以下内容:
- 暗阈值是直方图中指定数量像素的像素值小于或等于阈值的值。
- 亮阈值,是直方图中指定数量像素的像素值大于或等于阈值的值。
两个阈值之间的区域定义了中间色调,即您认为对图像至关重要的像素值。
示例: 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 轻松设置参数。