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

Shading Correction#

Shading Correction camera feature 可讓您減少因感光元件畫素光敏感度不同而在影像中產生的非均勻性。同時也能將照明和照明光學元件造成的偽影減到最低。

Shading Correction 是根據儲存在相機上且包含適當校正資料的檔案所進行的。在影像擷取期間,這些資料會套用到原始畫素值,進而改善影像。

Shading Correction 功能僅適用於 racer 2 相機。

使用此功能#

運作原理#

DSNU 與 PRNU 校正#

Shading Correction 可將由暗電流訊號非均勻性 (DSNU) 和光響應非均勻性 (PRNU) 所引起的影像偽影降至最低。相機提供以下兩種 Shading Correction 類型:

  • DSNU correction:當相機在完全黑暗的環境中擷取線條時,該線條中的所有畫素值應接近零且應相等。實際上,感光元件中畫素效能的微小變化,會導致相機在黑暗中擷取線條時,輸出的畫素值產生一些變化。DSNU correction 可針對此類變化進行校正。其運作方式是將個別的灰階值(偏移量)新增至所擷取線條中的每個畫素值。

  • PRNU correction:當相機對準明亮且均勻照明的表面擷取線條時,該線條中的所有畫素值應接近其最大灰階值且應相等。實際上,感光元件中畫素效能的微小變化以及光學和照明的變化,會導致相機輸出的畫素值產生變化。PRNU correction 可針對此類變化進行校正。其運作方式是將個別的乘數(增益)套用到所擷取線條中的每個畫素值。

Shading Correction 是一種逐畫素校正方法,亦即會為每一個單獨的畫素計算校正值。

資訊

您可以將相機設定為僅執行 DSNU correction、僅執行 PRNU correction,或執行這兩種 Shading Correction。如果您執行這兩種 Shading Correction,相機會先執行 DSNU correction,然後再執行 PRNU correction。

Shading Correction 設定集#

用於 DSNU correction 和 PRNU correction 的校正值會儲存在稱為 shading correction sets 的檔案中。有以下兩種類型:

  • Factory correction set:包含在相機生產過程中儲存在相機上的校正值。Factory correction set 只能減少由暗電流訊號非均勻性 (DSNU) 引起的影像偽影。

  • User correction set:包含必須由使用者建立並儲存在相機上的校正值。根據您的相機型號,您最多可以建立 32 個 User correction set。

    您可以下載或上傳 User shading correction 檔案。

下載 Shading Correction 檔案#

資訊

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

若要使用 pylon Viewer 下載 Shading correction 檔案:

  1. 在 pylon Viewer 中,開啟您要從中下載 Shading correction 資料檔案的相機。
  2. 在 pylon Viewer 的 Camera 功能表中,按一下 File Access。
  3. 在 Camera File 下拉方塊中,根據您要下載的檔案選取 PRNU Correction 或 DSNU Correction。
    如果沒有適當的項目,表示您的相機不支援下載 Shading correction 檔案。
  4. 按一下 Download,瀏覽至您要儲存檔案的目錄,然後輸入所需的檔案名稱。
  5. 按一下 Save。
  6. 關閉 Camera File Access 對話方塊。

上傳 Shading Correction 檔案#

資訊

  • 如果您將 Shading Correction 檔案上傳到相機,請確保所選的校正集是在您載入校正資料的相機上建立的。
  • Basler 強烈建議不要上傳經過編輯的 Shading Correction 檔案。

若要使用 pylon Viewer 上傳 Shading Correction 檔案:

  1. 在 pylon Viewer 中,開啟您要上傳 Shading Correction 資料檔案的相機。
  2. 在 pylon Viewer 的 Camera 功能表中,按一下 File Access。
  3. 在 Camera File 下拉方塊中,選取 PRNU Correction 或 DSNU Correction。
    如果沒有 PRNU Correction 或 DSNU Correction 項目,則表示您的相機不支援上傳校正檔案。
  4. 按一下 Upload 並瀏覽至您要上傳的檔案。
  5. 按一下 Open。
  6. 關閉 Camera File Access 對話方塊。

若要在上傳後套用 Shading Correction 檔案,請確保 BslShadingCorrectionMode 參數已設定為 User 會設為 BslShadingCorrectionSetIndex 參數已設定為對應的索引編號。

Shading Correction Mode#

Shading Correction 模式決定了 Shading Correction 是基於原廠儲存的值還是使用者校正集。

若要設定 Shading Correction 模式,請設定 BslShadingCorrectionMode 參數設為下列其中一個值:

  • Factory (預設值):Shading Correction 基於儲存在 factory 校正集中的值。
  • User:Shading Correction 基於儲存在 user 校正集中的值。
  • Off:相機 不會 執行 Shading Correction。

建立 Shading Correction Set#

在開始建立使用者自訂的 Shading Correction 集之前,您需要以下項目:

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

資訊

  • 為獲得最佳效果,請按照正常操作調整光學元件、行頻、Exposure Time、增益和相機溫度。Basler 建議在您的實際應用環境中擷取黑場和白場影像。
  • racer 2 L 相機:在 Dual(或 Quad)Line 感測器擷取模式中,在 Single(或 Dual)Line 模式下建立的 Shading Correction 集的狀態將顯示為空(BslShadingCorrectionSetStatus = Empty),儘管此集中已經存在校正資料。
    如果您想在 Dual 或 Quad Line 模式下建立新的 Shading Correction 集,請檢查在行數較少的模式下建立的校正集的索引編號。如果索引編號已被佔用,請為您的新集選擇其他編號。否則,校正資料將被新的校正值覆蓋和取代。

DSNU Correction Set#

若要為 DSNU correction 建立 Shading Correction 集:

  1. 防止任何光線照射到相機感測器上,例如在鏡頭上放置塑膠蓋。
  2. 將 BslShadingCorrectionSelector 參數設為 DSNU.
  3. 將 BslShadingCorrectionMode 參數設為 User.
  4. 將 BslShadingCorrectionSetIndex 參數設定為要建立的集的所需索引編號,例如 1。
  5. 將 BslShadingCorrectionROISelector 參數設定為所需的 Shading Correction ROI,例如 ROI 1。
  6. 若有需要,請使用下列參數設定 Shading Correction ROI 的位置與大小:
    • BslShadingCorrectionROIOffsetX:Shading Correction ROI 從感測器左側開始的水平偏移(以像素為單位)。
    • BslShadingCorrectionROIWidth: Shading Correction ROI 的寬度(以像素為單位)。
  7. 按一下 pylon Viewer 工具列中的 Continuous Shot 按鈕以開始擷取影像。
  8. 執行 BslShadingCorrectionSetCreate 用於建立新的 Shading Correction Set 的指令。
    總共會擷取並評估 256 張暗場影像。隨後會產生產生的 DSNU 矯正資料,收集於所定義的 Shading Correction Set 中,並儲存至相機的快閃 Memory 中。如果例如索引編號為 1 的 Shading Correction Set 已經包含矯正資料,這些資料將會被覆寫並由新的矯正值取代。

    資訊

    如果在建立 DSNU 矯正資料時啟用了 PRNU Correction Set,計算時將會忽略 PRNU 矯正值。

    建立的 Shading Correction Set 會自動啟用。

  9. 若要驗證 Shading Correction Set 建立的結果,請取得以下項目的值: BslShadingCorrectionSetCreateResult 參數的值。

PRNU Correction Set#

若要為 PRNU correction 建立 Shading Correction Set:

  1. 將感測器均勻照明至 70% 飽和度,例如,透過在相機的整個視野中放置一張白紙。
  2. 將 BslShadingCorrectionSelector 參數設為 PRNU.
  3. 將 BslShadingCorrectionMode 參數設為 User.
  4. 將 BslShadingCorrectionSetIndex 將參數設定為要建立的集合的所需索引編號,例如 2。
  5. 將 BslShadingCorrectionROISelector 參數設定為所需的 Shading Correction ROI,例如 ROI 1。
  6. 若有需要,請使用下列參數設定 Shading Correction ROI 的位置與大小:
    • BslShadingCorrectionROIOffsetX:Shading Correction ROI 從感測器左側開始的水平偏移(以像素為單位)。
    • BslShadingCorrectionROIWidth: Shading Correction ROI 的寬度(以像素為單位)。
  7. 按一下 pylon Viewer 工具列中的 Continuous Shot 按鈕以開始擷取影像。
  8. 執行 BslShadingCorrectionSetCreate 用於建立新的 Shading Correction Set 的指令。
    總共會擷取並評估 256 張亮場影像。隨後會產生產生的 PRNU 矯正資料,收集於所選取的 Shading Correction Set 中,並儲存至相機的快閃 Memory 中。如果例如索引編號為 2 的 Shading Correction Set 已經包含矯正資料,這些資料將會被覆寫並由新的矯正值取代。

    資訊

    如果在建立 PRNU 矯正資料時啟用了 DSNU Correction Set,計算時將會納入 DSNU 矯正值。

    建立的 Shading Correction Set 會自動啟用。

  9. 若要驗證 Shading Correction Set 建立的結果,請取得以下項目的值: BslShadingCorrectionSetCreateResult 參數的值。

  10. 如有必要,請調整 Target Gray Value for PRNU Correction 並重複步驟 7。如果您使用的是彩色相機,請分別為每個顏色通道調整 Target Gray Value for PRNU Correction,並重複步驟 7。

調整 PRNU Correction 的目標灰階值#

在 建立 PRNU Correction Set 期間,相機會在亮場影像中偵測最大亮度值。不過,您可能會想要調整您想要達到的感光元件亮度的相對目標灰階值。可能的原因包括例如:

  • 無法建立您的 Shading Correction Set,因為矯正值超出了允許的範圍。
  • 影像上的亮點(例如由反光所造成)會導致相機在建立矯正集期間偵測到高最大亮度值。您可能會想要降低這個與計算矯正資料相關的值,以改善您的矯正資料。

若要調整 Target Gray Value for PRNU Correction:

  1. 將 BslShadingCorrectionTargetSelector 參數設為下列其中一個值:
    • All (僅限單色相機):目標灰階值會套用到所有感光元件線條。
    • Red, Green, Blue (僅限彩色相機):目標灰階值會套用到各自的顏色通道。
  2. 將 BslShadingCorrectionTargetValue 參數設為所需的相對目標灰階值。
  3. 如果您使用的是彩色相機,請重複步驟 1 和 2,將所需的目標灰階值套用到其他顏色通道。

資訊

  • 影像 BslShadingCorrectionTargetValue 參數僅能在以下情況下使用: 建立 PRNU Correction Sets.
  • 僅會矯正絕對目標灰階值低於最大測得值之值的像素。
  • 對於在 Dual 或 Quad Line Sensor Acquisition Mode 下運作的 racer 2 L 相機,調整目標灰階值可能會呈現無法預期的結果。請改用 Single Line 模式與單色 Pixel Format。

其他參數:

  • BslShadingCorrectionAbsoluteTargetValue:感光元件亮度的絕對目標值。這是根據您相機的 Sensor Bit Depth 計算出的實際亮度值。
  • BslShadingCorrectionMaximumMeasuredValue:相機在以下期間偵測到的最大亮度值: 建立 Shading Correction 集合.

啟用 Shading Correction Set#

若要啟用 Shading Correction 集合:

  1. 將 BslShadingCorrectionMode 參數設為 User,如果您想要啟用使用者自訂的校正集合,或 Factory,如果您想要啟用原廠校正集合。
  2. 將 BslShadingCorrectionSetIndex 參數設為要使用的設定集索引編號,例如索引編號 2。

    Shading Correction 集合會自動啟用。

  3. 若要驗證此程序是否成功,請取得 BslShadingCorrectionSetStatus 參數的值。如果該值為 Ok,則表示 Shading 集合已成功啟用。相機現在會根據所選 Shading Correction 集合中的校正值來執行 Shading Correction。

資訊

您可以在影像擷取期間變更 Shading Correction 集合。不過,在此過程中可能會產生輕微的影像偽影。

停用 Shading Correction#

若要停用 Shading Correction,請將 BslShadingCorrectionMode 參數設為 Off.

詳細資料#

下表顯示適用於 racer 2 相機的 Shading 集合數量。

相機型號 Max. Number of Lines Exposed per Acquisition Available Number of Shading Corrections Sets
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

您也可以使用 pylon Viewer 來輕鬆設定參數。