跳至內容
測試伺服器
開發伺服器

Shading Correction#

「Shading Correction 」相機功能可協助您降低因感光元件像素光敏度差異所導致的影像不均勻現象。此外,亦能將由光源及照明光學元件所產生的偽影降至最低。

陰影校正是基於儲存於相機中且包含適當校正資料的檔案。在影像擷取過程中,這些資料會套用至原始像素值,從而提升影像品質。

「Shading Correction 」功能僅適用於Racer 2攝影機。

使用功能#

運作原理#

DSNU 與 PRNU 的更正#

陰影校正可將因暗訊號不均勻性(DSNU)及光電響應不均勻性(PRNU)所造成的影像瑕疵降至最低。本相機提供以下兩種陰影校正模式:

  • DSNU 校正:當相機在完全黑暗中捕捉一條線時,該線上的所有像素值應接近零,且數值應完全相等。實際上,感測器中各像素的性能會存在些微差異,這將導致相機在黑暗中捕捉線條時,輸出的像素值出現一定程度的波動。DSNU 校正正是用來修正此類波動。其運作原理是對所擷取線條中的每個像素值,分別加上一個獨立的灰階值(偏移量)。

  • PRNU 校正:當相機對準明亮且光線均勻的表面並捕捉一條線時,該條線上的所有像素值應接近其最大灰度值,且這些值應相等。 實際上,感光元件中各像素的性能存在微小差異,加上光學系統與照明條件的變化,都會導致相機輸出的像素值產生波動。PRNU 校正正是用來修正這類波動。其運作原理是針對所擷取線條中的每個像素值,分別套用一個獨立的乘數(增益)。

陰影校正是一種像素對像素的校準方法,也就是說,會針對每個單一像素計算出一個校正值。

資訊

您可以將相機設定為僅執行 DSNU 校正、僅執行 PRNU 校正,或是同時執行這兩種類型的陰影校正。若同時執行這兩種類型的陰影校正,相機會先執行 DSNU 校正,再執行 PRNU 校正。

Shading Correction 集合#

用於 DSNU 和 PRNU 校正的校正值,儲存於稱為「陰影校正集」的檔案中。其類型分為以下兩種:

  • 出廠校正集:包含在相機生產過程中儲存於相機內的校正值。出廠校正集僅能減少因暗訊號不均勻性(DSNU)所造成的影像瑕疵。

  • 使用者校正組:包含必須由使用者建立並儲存於相機中的校正值。視相機型號而定,您最多可建立 32 組使用者校正組。

    您可以下載或上傳使用者著色校正檔案。

下載Shading Correction 檔案#

資訊

  • 下載您的陰影校正檔案,有助於備份您的校正資料。
  • Basler 強烈建議您在執行韌體更新之前,先備份您的校正檔案。
  • 請勿編輯已下載的陰影校正檔案。

若要使用pylon Viewer 下載色階校正檔案:

  1. 在「pylon Viewer 」中,開啟您要從中下載著色校正資料檔案的相機。
  2. 在 pylon Viewer 的 Camera 選單中,按一下 File Access。
  3. 在「相機檔案」下拉式選單中,請根據您要下載的檔案類型,選擇「PRNU 校正」或「DSNU 校正」。
    若未出現相應選項,表示您的相機不支援下載陰影校正檔案。
  4. 點擊「下載」,瀏覽至您要儲存檔案的目錄,並輸入所需的檔案名稱。
  5. 按一下 Save。
  6. 關閉 Camera File Access 對話方塊。

上傳Shading Correction 檔案#

資訊

  • 若您將使用者陰影校正檔案上傳至相機,請務必確認所選的校正組是在您載入校正資料的那台相機上所建立的。
  • Basler 強烈建議不要上傳經過編輯的用戶陰影校正檔案。

若要使用 pylon Viewer:

  1. 在「pylon Viewer 」中,開啟您要上傳著色校正資料檔案的相機。
  2. 在 pylon Viewer 的 Camera 選單中,按一下 File Access。
  3. 在「相機檔案」下拉式選單中,請選擇「PRNU 校正」或「DSNU 校正」。
    若未出現「PRNU 校正」或「DSNU 校正」選項,表示您的相機不支援上傳校正檔案。
  4. 點擊「上傳」,然後瀏覽至您要上傳的檔案。
  5. 按一下 Open。
  6. 關閉 Camera File Access 對話方塊。

若要在上傳後套用陰影校正檔案,請確保 BslShadingCorrectionMode 參數設為 User 及 BslShadingCorrectionSetIndex 該參數被設定為對應的索引號碼。

Shading Correction 模式#

陰影校正模式決定陰影校正應依據工廠預設值,還是依據使用者設定的校正值進行。

要設定陰影校正模式,請設定 BslShadingCorrectionMode 參數設定為以下值之一:

  • Factory (預設):陰影校正是根據儲存於 工廠 修正集。
  • User: 陰影校正是根據儲存於 使用者 修正集。
  • Off: 這台相機會 不 執行陰影修正。

建立「Shading Correction 」套組#

在開始建立使用者自訂的陰影校正集之前,您需要準備以下項目:

  • 可用於完全覆蓋鏡頭的適當物件,例如鏡頭蓋
  • 一個背景均勻的目標,例如一張白紙

資訊

  • 為獲得最佳效果,請如同進行正常操作時那樣,調整光學系統、傳輸速率、曝光時間、增益及相機溫度。Basler 建議您在實際應用環境中擷取暗場與明場影像。
  • racer 2 L 攝影機:雙線(或四線)配置 感測器擷取模式, 在「單線」(或「雙線」)模式下建立的陰影校正集,其狀態將顯示為空(BslShadingCorrectionSetStatus = 空),儘管此資料集中已存在校正資料。
    若要在「雙線」或「四線」模式下建立新的陰影校正集,請檢查您在線數較少的模式下所建立之校正集的索引編號。若某個索引編號已被佔用,請為新校正集選擇另一個編號;否則,校正資料將會被覆寫,並由新的校正值取代。

DSNU 修正套件#

要建立用於DSNU 校正的陰影校正集:

  1. 請避免任何光線照射到相機的感光元件,例如在鏡頭上蓋上塑膠蓋。
  2. 將相機中的 BslShadingCorrectionSelector 參數設為 DSNU.
  3. 將相機中的 BslShadingCorrectionMode 參數設為 User.
  4. 將相機中的 BslShadingCorrectionSetIndex 將參數設定為要建立的集合的目標索引號,例如 1。
  5. 將相機中的 BslShadingCorrectionROISelector 將參數設定為所需的陰影校正 ROI,例如 ROI 1。
  6. 如有需要,可透過以下參數設定陰影校正 ROI 的位置與大小:
    • BslShadingCorrectionROIOffsetX: 陰影校正 ROI 距離感測器左側的水平偏移量(以像素為單位)。
    • BslShadingCorrectionROIWidth: 陰影校正 ROI 的寬度(以像素為單位)。
  7. 點擊「pylon Viewer 」工具列中的「連續拍攝」按鈕,即可開始進行影像擷取。
  8. 執行 BslShadingCorrectionSetCreate 用於建立新著色修正集的指令。
    共擷取並評估了 256 張暗場影像。隨後生成相應的 DSNU 校正資料,並將其彙整至已定義的陰影校正集內,最後儲存至相機的快閃記憶體中。若某個陰影校正集(例如編號為 1 的集)已包含校正資料,則原有資料將被覆寫,並替換為新的校正值。

    資訊

    若在建立 DSNU 校正資料時啟用了 PRNU 校正集,則計算時將忽略 PRNU 校正值。

    所建立的陰影校正集會自動啟用。

  9. 要驗證陰影修正集建立的結果,請取得 BslShadingCorrectionSetCreateResult 參數中選擇性地指定 HTML 記錄檔 (*.html) 的路徑與檔名。

PRNU 校正套組#

要建立用於PRNU 校正的陰影校正集:

  1. 請將感光元件均勻地照亮至 70% 飽和度,例如在相機的整個視野內放置一張白紙。
  2. 將相機中的 BslShadingCorrectionSelector 參數設為 PRNU.
  3. 將相機中的 BslShadingCorrectionMode 參數設為 User.
  4. 將相機中的 BslShadingCorrectionSetIndex 將參數設為要建立的集合的目標索引號,例如 2。
  5. 將相機中的 BslShadingCorrectionROISelector 將參數設定為所需的陰影校正 ROI,例如 ROI 1。
  6. 如有需要,可透過以下參數設定陰影校正 ROI 的位置與大小:
    • BslShadingCorrectionROIOffsetX: 陰影校正 ROI 距離感測器左側的水平偏移量(以像素為單位)。
    • BslShadingCorrectionROIWidth: 陰影校正 ROI 的寬度(以像素為單位)。
  7. 點擊「pylon Viewer 」工具列中的「連續拍攝」按鈕,即可開始進行影像擷取。
  8. 執行 BslShadingCorrectionSetCreate 用於建立新著色修正集的指令。
    共擷取並評估了 256 張高亮度影像。隨後生成的 PRNU 校正資料,會彙整至所選的陰影校正集,並儲存至相機的快閃記憶體中。若某個陰影校正集(例如索引號為 2 的集)已包含校正資料,則原有資料將被覆寫,並以新的校正值取代。

    資訊

    若在建立 PRNU 校正資料時啟用了 DSNU 校正集,則計算時會將 DSNU 校正值納入考量。

    所建立的陰影校正集會自動啟用。

  9. 要驗證陰影修正集建立的結果,請取得 BslShadingCorrectionSetCreateResult 參數中選擇性地指定 HTML 記錄檔 (*.html) 的路徑與檔名。

  10. 如有需要,請調整PRNU 校正的目標灰階值,並重複步驟 7。若使用彩色攝影機,請分別針對每個色彩通道調整 PRNU 校正的目標灰階值,並重複步驟 7。

調整 PRNU 校正的目標灰度值#

在建立 PRNU 校正集時,相機會偵測亮場影像中的最大亮度值。然而,您可能希望調整欲達成的感測器亮度的相對目標灰階值。可能的原因包括(例如):

  • 無法建立您的陰影校正集,因為校正值超出允許範圍。
  • 影像中的亮點(例如由光線反射所造成)會導致相機在建立校正資料集時偵測到較高的最大亮度值。您可能需要降低此值(該值與校正資料的計算相關),以改善校正資料的品質。

若要調整 PRNU 校正的目標灰階值:

  1. 將相機中的 BslShadingCorrectionTargetSelector 參數設定為以下值之一:
    • All (僅限單色相機):目標灰度值將套用至所有感測器行。
    • Red, Green, Blue (僅限彩色攝影機):目標灰度值將套用至對應的色彩通道。
  2. 將相機中的 BslShadingCorrectionTargetValue 將參數調整至所需的相對目標灰階值。
  3. 若您使用的是彩色相機,請重複步驟 1 和 2,將所需的目標灰階值套用至其他色彩通道。

資訊

  • 當 BslShadingCorrectionTargetValue 該參數僅能在以下情況下使用: 建立 PRNU 校正集.
  • 僅會對絕對目標灰階值低於最大測量值的像素進行校正。
  • 對於在雙 線或四線 感測器擷取模式下運作的racer 2 L 相機,調整目標灰度值可能會產生無法預期的結果。請改用單線模式並採用單色像素格式。

其他參數:

  • BslShadingCorrectionAbsoluteTargetValue: 感測器亮度的絕對目標值。這是根據相機感測器的位元深度所計算出的實際亮度值。
  • BslShadingCorrectionMaximumMeasuredValue: 攝影機在 建立 PRNU 修正集.

啟用「Shading Correction 」集#

若要啟用陰影校正組:

  1. 將相機中的 BslShadingCorrectionMode 參數設為 User, 若您想啟用自訂校正集,或要 Factory, 若您想啟用工廠校正設定。
  2. 將相機中的 BslShadingCorrectionSetIndex 將參數設定為要使用的集合的索引號,例如索引號 2。

    陰影校正套件會自動啟用。

  3. 要驗證此流程是否成功,請取得 BslShadingCorrectionSetStatus 參數。若該值為 Ok, 陰影設定集已成功啟用。相機現在會根據所選陰影校正設定集中的校正值,執行陰影校正。

資訊

在影像擷取過程中,可以變更陰影校正組。不過,在此過程中可能會產生輕微的影像瑕疵。

停用Shading Correction#

若要停用陰影校正,請將 BslShadingCorrectionMode 參數設為 Off.

詳細資料#

下表顯示了賽車手 2相機可用的著色集數量。

相機型號 每次擷取可顯示的行數上限 可用的陰影校正組數量
r2L2048-29gc 3 10
r2L2048-58gm 1 32
r2L2048-62g5c 3 10
r2L2048-62cc 3 10
r2L2048-172cm 1 32
r2L2048-172g5m 1 32
r2L4096-14gc 2 16
r2L4096-29gm 1 32
r2L4096-42cc 2 16
r2L4096-42g5c 2 16
r2L4096-84cm 1 32
r2L4096-84g5m 1 16
r2L8192-80cc 3 10
r2L8192-240cm 4 8
r2L16384-60cc 2 16
r2L16384-120cm 2 16
r2T16416-500cm 1 32

範例程式碼#

// Set the type of shading correction to DSNU
camera.BslShadingCorrectionSelector.SetValue(BslShadingCorrectionSelector_DSNU);
// Or for PRNU: Set the type of shading correction to PRNU
camera.BslShadingCorrectionSelector.SetValue(BslShadingCorrectionSelector_PRNU);

// Note: Valid for DSNU and PRNU:
// Set the shading correction mode to User
camera.BslShadingCorrectionMode.SetValue(BslShadingCorrectionMode_User);
// Set the desired index number of the set to be created
camera.BslShadingCorrectionSetIndex.SetValue(1);
// Set the shading correction ROI selector to ROI 1
camera.BslShadingCorrectionROISelector.SetValue(BslShadingCorrectionROISelector_ROI1);
// Set the offset X of the ROI to 0
camera.BslShadingCorrectionROIOffsetX.SetValue(0);
// Set the ROI width to 2048
camera.BslShadingCorrectionROIWidth.SetValue(2048);

// Note: Valid for PRNU only:
// Set the shading correction target selector to red
camera.BslShadingCorrectionTargetSelector.SetValue(BslShadingCorrectionTargetSelector_Red);
// Set the shading correction target value for red to 1000
camera.BslShadingCorrectionTargetValue.SetValue(1.0000);
// Set the shading correction target selector to green
camera.BslShadingCorrectionTargetSelector.SetValue(BslShadingCorrectionTargetSelector_Green);
// Set the shading correction target value for green to 1000
camera.BslShadingCorrectionTargetValue.SetValue(1.0000);
// Set the shading correction target selector to blue
camera.BslShadingCorrectionTargetSelector.SetValue(BslShadingCorrectionTargetSelector_Blue);
// Set the shading correction target value for blue to 1000
camera.BslShadingCorrectionTargetValue.SetValue(1.0000);

// Note: Valid for DSNU and PRNU:
// Create new shading correction data for the shading correction set selected
camera.BslShadingCorrectionSetCreate.Execute();
// Get the status of the shading correction set selected
BslShadingCorrectionSetStatus setStatus = camera.BslShadingCorrectionSetStatus.GetValue();
INodeMap& nodemap = camera.GetNodeMap();
// Set the type of shading correction to DSNU
CEnumParameter(nodemap, "BslShadingCorrectionSelector").SetValue("DSNU");
// Or for PRNU: Set the type of shading correction to PRNU
CEnumParameter(nodemap, "BslShadingCorrectionSelector").SetValue("PRNU");

// Note: Valid for DSNU and PRNU:
// Set the shading correction mode to User
CEnumParameter(nodemap, "BslShadingCorrectionMode").SetValue("User");
// Set the desired index number of the set to be created
CIntegerParameter(nodemap, "BslShadingCorrectionSetIndex").SetValue(1);
// Set the shading correction ROI selector to ROI 1
CEnumParameter(nodemap, "BslShadingCorrectionROISelector").SetValue("ROI1");
// Set the offset X of the ROI to 0
CIntegerParameter(nodemap, "BslShadingCorrectionROIOffsetX").SetValue(0);
// Set the ROI width to 2048
CIntegerParameter(nodemap, "BslShadingCorrectionROIWidth").SetValue(2048);

// Note: Valid for PRNU only:
// Set the shading correction target selector to red
CEnumParameter(nodemap, "BslShadingCorrectionTargetSelector").SetValue("Red");
// Set the shading correction target value for red to 1000
CFloatParameter(nodemap, "BslShadingCorrectionTargetValue").SetValue(1.0000);
// Set the shading correction target selector to green
CEnumParameter(nodemap, "BslShadingCorrectionTargetSelector").SetValue("Green");
// Set the shading correction target value for green to 1000
CFloatParameter(nodemap, "BslShadingCorrectionTargetValue").SetValue(1.0000);
// Set the shading correction target selector to blue
CEnumParameter(nodemap, "BslShadingCorrectionTargetSelector").SetValue("Blue");
// Set the shading correction target value for blue to 1000
CFloatParameter(nodemap, "BslShadingCorrectionTargetValue").SetValue(1.0000);

// Note: Valid for DSNU and PRNU:
// Create new shading correction data for the shading correction set selected
CCommandParameter(nodemap, "BslShadingCorrectionSetCreate").Execute();
// Get the status of the shading correction set selected
String_t setStatus = CEnumParameter(nodemap, "BslShadingCorrectionSetStatus").GetValue();
// Set the type of shading correction to DSNU
camera.Parameters[PLCamera.BslShadingCorrectionSelector].SetValue(PLCamera.BslShadingCorrectionSelector.DSNU);
// Or for PRNU: Set the type of shading correction to PRNU
camera.Parameters[PLCamera.BslShadingCorrectionSelector].SetValue(PLCamera.BslShadingCorrectionSelector.PRNU);

// Note: Valid for DSNU and PRNU:
// Set the shading correction mode to User
camera.Parameters[PLCamera.BslShadingCorrectionMode].SetValue(PLCamera.BslShadingCorrectionMode.User);
// Set the desired index number of the set to be created
camera.Parameters[PLCamera.BslShadingCorrectionSetIndex].SetValue(1);
// Set the shading correction ROI selector to ROI 1
camera.Parameters[PLCamera.BslShadingCorrectionROISelector].SetValue(PLCamera.BslShadingCorrectionROISelector.ROI1);
// Set the offset X of the ROI to 0
camera.Parameters[PLCamera.BslShadingCorrectionROIOffsetX].SetValue(0);
// Set the ROI width to 2048
camera.Parameters[PLCamera.BslShadingCorrectionROIWidth].SetValue(2048);

// Note: Valid for PRNU only:
// Set the shading correction target selector to red
camera.Parameters[PLCamera.BslShadingCorrectionTargetSelector].SetValue(PLCamera.BslShadingCorrectionTargetSelector.Red);
// Set the shading correction target value for red to 1000
camera.Parameters[PLCamera.BslShadingCorrectionTargetValue].SetValue(1.0000);
// Set the shading correction target selector to green
camera.Parameters[PLCamera.BslShadingCorrectionTargetSelector].SetValue(PLCamera.BslShadingCorrectionTargetSelector.Green);
// Set the shading correction target value for green to 1000
camera.Parameters[PLCamera.BslShadingCorrectionTargetValue].SetValue(1.0000);
// Set the shading correction target selector to blue
camera.Parameters[PLCamera.BslShadingCorrectionTargetSelector].SetValue(PLCamera.BslShadingCorrectionTargetSelector.Blue);
// Set the shading correction target value for blue to 1000
camera.Parameters[PLCamera.BslShadingCorrectionTargetValue].SetValue(1.0000);

// Note: Valid for DSNU and PRNU:
// Create new shading correction data for the shading correction set selected
camera.Parameters[PLCamera.BslShadingCorrectionSetCreate].Execute();
// Get the status of the shading correction set selected
string setStatus = camera.Parameters[PLCamera.BslShadingCorrectionSetStatus].GetValue();
/* 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 */
size_t len = 0;
char setStatus_str[64] = {0};
/* Set the type of shading correction to DSNU */
errRes = PylonDeviceFeatureFromString(hdev, "BslShadingCorrectionSelector", "DSNU");
CHECK(errRes);
/* Or for PRNU: Set the type of shading correction to PRNU */
errRes = PylonDeviceFeatureFromString(hdev, "BslShadingCorrectionSelector", "PRNU");
CHECK(errRes);

/* Note: Valid for DSNU and PRNU: */
/* Set the shading correction mode to User */
errRes = PylonDeviceFeatureFromString(hdev, "BslShadingCorrectionMode", "User");
CHECK(errRes);
/* Set the desired index number of the set to be created */
errRes = PylonDeviceSetIntegerFeature(hdev, "BslShadingCorrectionSetIndex", 1);
CHECK(errRes);
/* Set the shading correction ROI selector to ROI 1 */
errRes = PylonDeviceFeatureFromString(hdev, "BslShadingCorrectionROISelector", "ROI1");
CHECK(errRes);
/* Set the offset X of the ROI to 0 */
errRes = PylonDeviceSetIntegerFeature(hdev, "BslShadingCorrectionROIOffsetX", 0);
CHECK(errRes);
/* Set the ROI width to 2048 */
errRes = PylonDeviceSetIntegerFeature(hdev, "BslShadingCorrectionROIWidth", 2048);
CHECK(errRes);

/* Note: Valid for PRNU only: */
/* Set the shading correction target selector to red */
errRes = PylonDeviceFeatureFromString(hdev, "BslShadingCorrectionTargetSelector", "Red");
CHECK(errRes);
/* Set the shading correction target value for red to 1000 */
errRes = PylonDeviceSetFloatFeature(hdev, "BslShadingCorrectionTargetValue", 1.0000);
CHECK(errRes);
/* Set the shading correction target selector to green */
errRes = PylonDeviceFeatureFromString(hdev, "BslShadingCorrectionTargetSelector", "Green");
CHECK(errRes);
/* Set the shading correction target value for green to 1000 */
errRes = PylonDeviceSetFloatFeature(hdev, "BslShadingCorrectionTargetValue", 1.0000);
CHECK(errRes);
/* Set the shading correction target selector to blue */
errRes = PylonDeviceFeatureFromString(hdev, "BslShadingCorrectionTargetSelector", "Blue");
CHECK(errRes);
/* Set the shading correction target value for blue to 1000 */
errRes = PylonDeviceSetFloatFeature(hdev, "BslShadingCorrectionTargetValue", 1.0000);
CHECK(errRes);

/* Note: Valid for DSNU and PRNU: */
/* Create new shading correction data for the shading correction set selected */
errRes = PylonDeviceExecuteCommandFeature(hdev, "BslShadingCorrectionSetCreate");
CHECK(errRes);
/* Get the status of the shading correction set selected */
len = sizeof(setStatus_str);
errRes = PylonDeviceFeatureToString(hdev, "BslShadingCorrectionSetStatus", setStatus_str, &len);
CHECK(errRes);
# Set the type of shading correction to DSNU
camera.BslShadingCorrectionSelector.Value = "DSNU"
# Or for PRNU: Set the type of shading correction to PRNU
camera.BslShadingCorrectionSelector.Value = "PRNU"

# Note: Valid for DSNU and PRNU:
# Set the shading correction mode to User
camera.BslShadingCorrectionMode.Value = "User"
# Set the desired index number of the set to be created
camera.BslShadingCorrectionSetIndex.Value = 1
# Set the shading correction ROI selector to ROI 1
camera.BslShadingCorrectionROISelector.Value = "ROI1"
# Set the offset X of the ROI to 0
camera.BslShadingCorrectionROIOffsetX.Value = 0
# Set the ROI width to 2048
camera.BslShadingCorrectionROIWidth.Value = 2048

# Note: Valid for PRNU only:
# Set the shading correction target selector to red
camera.BslShadingCorrectionTargetSelector.Value = "Red"
# Set the shading correction target value for red to 1000
camera.BslShadingCorrectionTargetValue.Value = 1.0000
# Set the shading correction target selector to green
camera.BslShadingCorrectionTargetSelector.Value = "Green"
# Set the shading correction target value for green to 1000
camera.BslShadingCorrectionTargetValue.Value = 1.0000
# Set the shading correction target selector to blue
camera.BslShadingCorrectionTargetSelector.Value = "Blue"
# Set the shading correction target value for blue to 1000
camera.BslShadingCorrectionTargetValue.Value = 1.0000

# Note: Valid for DSNU and PRNU:
# Create new shading correction data for the shading correction set selected
camera.BslShadingCorrectionSetCreate.Execute()
# Get the status of the shading correction set selected
setStatus = camera.BslShadingCorrectionSetStatus.Value

您也可以 use the pylon Viewer 來輕鬆設定參數。