Tonal Range#
若要使用此功能,您必須熟悉 tonal range 與 image histograms 的概念。
如果您想自動調整色調範圍,請使用 Tonal Range Auto 功能。
如果您想使用線性或 S 曲線函數調整對比度,請使用 Brightness and Contrast 功能(若適用)。
使用此功能#
調整對比度#
資訊
Basler 建議優先使用 Tonal Range Auto 功能。之後,您可以按照以下說明微調對比度。
若要手動調整對比度:
- 請確保相機已經能產生良好的影像,僅剩 low contrast 或 shifted colors 等問題。色調範圍操作只能在已經具備良好 Quality 的影像上執行。
在最佳化影像 Quality 時,請遵循 sequence given below。 - 將
TonalRangeEnable參數設為On. - 將
TonalRangeSelector參數設為Sum. - 將
TonalRangeSourceDark和TonalRangeTargetDark參數設為 暗色來源與目標值.
如果暗色目標值 lower 小於暗色來源值,對比度就會增加。 - 將
TonalRangeSourceBright和TonalRangeTargetBright參數設為 亮色來源與目標值.
如果亮色目標值 大於 亮色來源值,對比度就會增加。
校正偏色#
資訊
Basler 建議優先使用 Tonal Range Auto 功能。之後,您可以按照以下說明微調色彩校正。
若要手動校正偏色:
- 請確保相機已經能產生良好的影像,僅剩 low contrast 或 shifted colors 等問題。色調範圍操作只能在已經具備良好 Quality 的影像上執行。
在最佳化影像 Quality 時,請遵循 sequence given below。 - 將
TonalRangeEnable參數設為On. - 將
TonalRangeSelector參數設為Red,Green或Blue,具體取決於您要校正的偏色。
範例: 如果您的影像帶有綠色色偏,請將參數設定為Green. - 將
TonalRangeSourceDark,TonalRangeTargetDark,TonalRangeSourceBright的狀態,以及TonalRangeTargetBright參數設為 來源與目標值 將目前直方圖與其他直方圖進行對齊。
影像最佳化順序#
若要最佳化影像 Quality,請按照以下順序操作以避免產生副作用:
- 使用 Exposure Time、Black Level 和 Gain 功能進行基本的影像最佳化。確保影像沒有過度曝光。
- 如果您使用的是彩色相機,請使用 Light Source Preset、Balance White Auto 或 Balance White 功能調整白平衡。
- 使用 Tonal Range Auto 和 Tonal Range 功能來最佳化對比度、色彩或兩者。
運作原理#
要理解色調範圍操作,最好透過檢視影像中色調分佈的圖形表示(即 image histogram)來進行。
Basler pylon Viewer 提供 Histogram 窗格,這在執行色調範圍操作時非常有用。
資訊
根據相機上啟用的其他功能而定,pylon Viewer 中的 Histogram 窗格可能不會顯示 Tonal Range 功能實際使用的資料。
例如,Gamma 功能是在色調範圍操作之後處理的。因此,pylon Viewer 中顯示的直方圖包含伽瑪校正,但 Tonal Range 功能所使用的資料則不包含。
來源與目標值#
對比度和色彩調整都基於將 source 值對應到 target值的相同概念。
為了說明這一點,您可以將 source 值想像為直方圖中的「錨點」,而 target 值則是錨點移動到的位置。

當 source 值對應到 target 值時,整個直方圖會相應地擴展或拉伸:

Dark/Bright Source and Target Values#
如上圖所示,必須定義兩組 source 和 target 值才能執行色調範圍操作:
- Dark source 和 target 值,位於 lower 直方圖的尾端。
您可以使用以下方式指定這些值:TonalRangeSourceDark和TonalRangeTargetDark參數的狀態。 - Bright source 和 target 值,位於 upper 直方圖的尾端。
您可以使用以下方式指定這些值:TonalRangeSourceBright和TonalRangeTargetBright參數的狀態。
所有 source 和 target 值的範圍可以從 0 到最大像素值(例如,如果設定了 12 位元 Pixel Format,則為 4095)。由於直方圖拉伸和擴展的程度有限,參數範圍也可能受到限制。
對比度調整(黑白與彩色相機)#
在支援 Tonal Range 功能的所有相機上,您都可以使用該功能來調整對比度。
低對比度影像具有狹窄的色調範圍:

利用 Tonal Range 功能,您可以手動加寬 Tonal Range,進而增加對比度。

加寬 Tonal Range 的方式是將 dark source value 對應至較低的目标值,並將 bright source value 對應至較高的目标值。
這兩個來源值之間的區域定義了您的中間調,也就是您認為對影像至關重要的像素值。
若要自動執行此程序,請使用 Tonal Range Auto 功能。
色彩校正(僅限彩色相機)#
在支援 Tonal Range 功能的彩色相機上,您也可以使用此功能來校正色彩偏差。
如果您影像中的色彩發生偏差,三個 RGB(紅、綠、藍)色階分佈圖將會無法對齊。例如,如果您的影像偏紅,紅色色階分佈圖顯示的位置會比綠色和藍色色階分佈圖更靠右(請參閱以下範例)。
利用 Tonal Range 功能,您可以手動對齊 RGB 色階分佈圖,進而減少色彩偏差。

您可以透過設定 source and target values 來對齊 RGB 色階分佈圖,使所有色階分佈圖都能拉伸並移動至相近的起點與終點。
若要自動執行此程序,請使用 Tonal Range Auto 功能。
外部連結#
範例程式碼#
// Enable tonal range adjustments
camera.TonalRangeEnable.SetValue(TonalRangeEnable_On);
// Specify that the summed RGB pixel values are used for tonal range adjustments
camera.TonalRangeSelector.SetValue(TonalRangeSelector_Sum);
// Set the dark source and target values
camera.TonalRangeSourceDark.SetValue(30);
camera.TonalRangeTargetDark.SetValue(0);
// Set the bright source and target values
camera.TonalRangeSourceBright.SetValue(240);
camera.TonalRangeTargetBright.SetValue(255);
INodeMap& nodemap = camera.GetNodeMap();
// Enable tonal range adjustments
CEnumParameter(nodemap, "TonalRangeEnable").SetValue("On");
// Specify that the summed RGB pixel values are used for tonal range adjustments
CEnumParameter(nodemap, "TonalRangeSelector").SetValue("Sum");
// Set the dark source and target values
CIntegerParameter(nodemap, "TonalRangeSourceDark").SetValue(30);
CIntegerParameter(nodemap, "TonalRangeTargetDark").SetValue(0);
// Set the bright source and target values
CIntegerParameter(nodemap, "TonalRangeSourceBright").SetValue(240);
CIntegerParameter(nodemap, "TonalRangeTargetBright").SetValue(255);
// Enable tonal range adjustments
camera.Parameters[PLCamera.TonalRangeEnable].SetValue(PLCamera.TonalRangeEnable.On);
// Specify that the summed RGB pixel values are used for tonal range adjustments
camera.Parameters[PLCamera.TonalRangeSelector].SetValue(PLCamera.TonalRangeSelector.Sum);
// Set the dark source and target values
camera.Parameters[PLCamera.TonalRangeSourceDark].SetValue(30);
camera.Parameters[PLCamera.TonalRangeTargetDark].SetValue(0);
// Set the bright source and target values
camera.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_RESULT errRes = 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 adjustments
camera.TonalRangeEnable.Value = "On"
# Specify that the summed RGB pixel values are used for tonal range adjustments
camera.TonalRangeSelector.Value = "Sum"
# Set the dark source and target values
camera.TonalRangeSourceDark.Value = 30
camera.TonalRangeTargetDark.Value = 0
# Set the bright source and target values
camera.TonalRangeSourceBright.Value = 240
camera.TonalRangeTargetBright.Value = 255
您也可以使用 pylon Viewer 來輕鬆設定參數。