Defect Pixel Correction#
在獲取的影像中,即使使用了均勻光源,某些像素仍可能顯得比其他像素明顯更亮或更暗。此問題是由於各像素的靈敏度存在差異所致,而這種差異則源於製造公差。
使用功能#
此功能的實作方式會因相機而異:
ace 2 R/X、boost R 以及 dart M 相機#
Basler ace 2 R、ace 2 X 、boost R 以及 dart M 相機均支援靜態缺陷像素校正。此校正功能是基於儲存於相機中的檔案,該檔案內含缺陷像素座標清單。
「靜態」意指校正過程中始終使用相同的指定缺陷像素座標。在影像擷取過程中,會根據這些像素鄰近像素的亮度值,來替換恰好是這些像素的亮度值。
以下缺陷像素校正檔案可儲存於相機中:
- 工廠檔案:包含在相機生產過程中檢測到的缺陷像素座標。
- 使用者檔案:包含使用者自訂的座標。您可以將此檔案上傳至相機。這使您能夠定義隨著時間推移可能出現的新缺陷像素。
資訊
Baslerace 2 X 相機亦支援動態像素缺陷校正。如需更多資訊,請參閱 Pixel Correction Beyond。
使用pylon Viewer#
→ 請參閱「靜態缺陷像素修正」(pylon Viewer )。
使用pylon API#
設定靜態缺陷像素校正模式#
若要設定靜態缺陷像素校正模式,請將 BslStaticDefectPixelCorrectionMode 參數設定為以下值之一:
Factory(預設):靜態缺陷像素校正是基於儲存於 工廠 更正檔。User: 靜態缺陷像素校正是基於儲存於 使用者 更正檔。
請注意,當透過pylon API 設定此模式時, 僅 將使用使用者自訂的像素。在設定 User incl. Factory 透過 pylon Viewer, 除了工廠檔案中儲存的像素外,還會使用使用者自訂的像素。Off: 這台相機會 不 執行靜態缺陷像素校正。
上傳User Defect Pixel Correction 檔案#
上傳使用者缺陷像素修正檔案前,請確保該檔案符合以下檔案格式:
檔案必須以一個 4 位元組的標頭開頭,該標頭包含四個值為 0 的位元組。標頭之後,檔案必須包含缺陷像素的資料條目(最多可指定 4096 個缺陷像素)。每個資料條目由 32 位元組成,位元順序如下:14 位元為 y 座標、14 位元為 x 座標、4 位元為類型
範例:座標為 x = 1 及 y = 2 的缺陷像素資料
若要使用 pylon Viewer:
- 在 pylon Viewer 的 Camera 選單中,按一下 File Access。
- 在「相機檔案」下拉式選單中,請選取 User Defect Pixel Correction。
若無 User Defect Pixel Correction 項目,表示您的相機不支援上傳校正檔案。 - 點擊「上傳」,然後瀏覽至您要上傳的檔案。
- 按一下 Open。
若要在上傳後套用使用者自訂的缺陷像素修正檔,請確保 BslStaticDefectPixelCorrectionMode 參數設為 User 並執行 BslStaticDefectPixelCorrectionReload 指令。
下載缺陷像素修正檔案#
若您希望將自己測得的缺陷像素新增至已下載的檔案中,下載缺陷像素校正檔案(例如出廠校正檔案)可能會有所幫助。您可以將完整的缺陷像素清單儲存至一個新的使用者校正檔案中。
若要使用pylon Viewer 下載缺陷像素修正檔案:
- 在 pylon Viewer 的 Camera 選單中,按一下 File Access。
- 在「相機檔案」下拉式選單中,請根據您要下載的檔案類型,選擇「靜態工廠缺陷像素校正」或「靜態User Defect Pixel Correction 」。
若未出現相應選項,表示您的相機不支援下載檔案。 - 點擊「下載」,瀏覽至您要儲存檔案的目錄,並輸入所需的檔案名稱。
- 按一下 Open。
靜態缺陷像素校正檔案狀態#
當 StaticDefectPixelCorrectionFileStatus 該參數可取以下值:
FileStatusUnknown: 缺陷像素修正檔案的狀態不明。請拍攝一張影像以變更檔案狀態。FileOk: 缺陷像素校正檔案有效。FileNotFound: 找不到缺陷像素修正檔案。該檔案從未上傳過,或是已被刪除。FileEmpty: 缺陷像素校正檔案中沒有任何條目。檔案標頭有效,但檔案中並未包含任何缺陷像素。缺陷像素校正程序已中止。InvalidHeader: 缺陷像素校正檔案的標頭無效。該檔案必須具有 4 位元組的檔案標頭。InvalidSize: 缺陷像素校正檔案的大小不正確。缺陷像素的最大數量不得超過 4096。InvalidSorting: 缺陷像素修正檔案中的項目排序不正確。缺陷像素修正程序已中止。InvalidFileEntry: 缺陷像素校正檔案中至少有一筆記錄的大小不正確。缺陷像素校正程序已中止。InvalidClustering: 已偵測到一個無效簇。若連續三個或更多相鄰像素被視為一個無效簇。位於其他缺陷像素之間的任何缺陷像素均無法修正。
缺陷像素修正檔案中最多可包含一定數量的缺陷像素。要取得該數值,請取得 BslStaticDefectPixelCorrectionMaxDefects 參數中選擇性地指定 HTML 記錄檔 (*.html) 的路徑與檔名。
boost V 相機#
Baslerboost V 相機支援靜態缺陷像素校正。此校正功能是基於儲存於相機中的檔案,該檔案內含缺陷像素座標清單。
「靜態」意指校正過程中始終使用相同的指定缺陷像素座標。在影像擷取過程中,會根據這些像素鄰近像素的亮度值,來替換恰好是這些像素的亮度值。
執行 Defect Pixel Correction#
資訊
pylon Viewer 的內建「靜態缺陷像素校正」功能不支援boost V 相機。
請使用「pylon Viewer 」或「pylon API 」的功能樹,對「boost V 」相機進行缺陷像素校正。
要在boost V 相機上執行缺陷像素校正:
-
將相機中的
BslStaticDefectPixelCorrectionMode設定參數至所需的校正模式:Factory: 僅會修正其座標已儲存於工廠檔案中的缺陷像素。工廠檔案是在相機生產過程中生成的,且無法進行修改。User: 您可以指定自訂的缺陷像素座標。Off: 這台相機會 不 執行靜態缺陷像素校正。
-
如果您選擇了
User:- 找出圖片中的像素錯誤,並記錄出這些缺陷像素的 x 和 y 座標。
- 將相機中的
BslStaticDefectPixelCorrectionYCoordinate參數傳遞至 y 第一個缺陷像素的座標。 - 將相機中的
BslStaticDefectPixelCorrectionXSelector參數設為X0. - 將相機中的
BslStaticDefectPixelCorrectionXCoordinate參數傳遞至 x 第一個缺陷像素的座標。 - 如果還有另一個 y 座標相同、但 x 座標不同的缺陷像素,請設定
BslStaticDefectPixelCorrectionXSelector將參數傳遞至下一個條目,例如:X1,並輸入下一個 x 座標。 - 針對其餘所有像素錯誤,請重複步驟 b 至 e。
- 執行
BslStaticDefectPixelCorrectionSave用以將變更儲存至快閃記憶體的指令。
資訊
- 您可以使用
BslStaticDefectPixelCorrectionCount用於檢查目前正在校正多少張圖片像素的參數。 - 您可以設定
BslStaticDefectPixelCorrectionTestMode參數設為On將所有經過修正的像素設為純白色。這有助於找出影像中正在被修正的像素。
移除缺陷像素座標#
工廠檔案中的像素座標無法移除。
不過,您可以移除自訂的缺陷像素座標,也就是在「使用者」校正模式下輸入的座標(參見上文)。操作步驟如下:
-
若要移除單一自訂缺陷像素的座標:
- 將相機中的
BslStaticDefectPixelCorrectionYCoordinate參數傳遞至 y 缺陷像素的座標。 - 將相機中的
BslStaticDefectPixelCorrectionXSelector傳入儲存缺陷像素 x 座標的條目之參數,例如:X0. - 將相機中的
BslStaticDefectPixelCorrectionXCoordinate將參數設為 0xFFFF。 - 執行
BslStaticDefectPixelCorrectionSave用以將變更儲存至快閃記憶體的指令。
- 將相機中的
-
若要移除所有自訂的缺陷像素座標:
- 執行
BslStaticDefectPixelCorrectionClearAll指令。這會將所有BslStaticDefectPixelCorrectionXCoordinate將參數值設為 0xFFFF。 - 執行
BslStaticDefectPixelCorrectionSave用以將變更儲存至快閃記憶體的指令。
- 執行
dart 和 pulse 攝影機#
Basler 的dart 及 pulse 相機可執行兩種類型的像素校正:
- 靜態像素校正功能會校正那些亮度值明顯低於鄰近像素的像素,其中包括完全黑色的像素。
- 動態像素校正功能會針對那些亮度值明顯高於鄰近像素的像素進行校正,其中包含完全白色的像素。系統會根據內建的閾值來判定何時將某個像素識別為「熱像素」。「動態」意指系統會針對每張擷取的影像,分別計算缺陷像素的校正值。
設定缺陷像素修正模式#
要設定缺陷像素校正模式,請設定 BslDefectPixelCorrectionMode 參數設定為以下值之一:
On(預設):相機執行 靜態與動態 像素修正。StaticOnly: 相機執行 靜態 僅進行像素校正。Off: 這台相機會 不 執行像素校正。
範例程式碼#
ace 2 R/X、boost R 以及 dart M 相機#
/* 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 */
/* Set static user defect pixel correction */
errRes = PylonDeviceFeatureFromString(hdev, "BslStaticDefectPixelCorrectionMode", "User");
CHECK(errRes);
/* Reload static defect pixel correction file */
errRes = PylonDeviceExecuteCommandFeature(hdev, "BslStaticDefectPixelCorrectionReload");
CHECK(errRes);
boost V 相機#
// Set the defect pixel correction mode to User
camera.BslStaticDefectPixelCorrectionMode.SetValue(BslStaticDefectPixelCorrectionMode_User);
// Assume there are two defect pixels at coordinates (120,430) and (182,430)
// Set the y coordinate to 430
camera.BslStaticDefectPixelCorrectionYCoordinate.SetValue(430);
// Select entry X0 and assign the first x coordinate
camera.BslStaticDefectPixelCorrectionXSelector.SetValue(BslStaticDefectPixelCorrectionXSelector_X0);
camera.BslStaticDefectPixelCorrectionXCoordinate.SetValue(120);
// Select entry X1 and assign the second x coordinate, which is in the same line
camera.BslStaticDefectPixelCorrectionXSelector.SetValue(BslStaticDefectPixelCorrectionXSelector_X1);
camera.BslStaticDefectPixelCorrectionXCoordinate.SetValue(182);
// Save changes to flash memory
camera.BslStaticDefectPixelCorrectionSave.Execute();
INodeMap& nodemap = camera.GetNodeMap();
// Set the defect pixel correction mode to User
CEnumParameter(nodemap, "BslStaticDefectPixelCorrectionMode").SetValue("User");
// Assume there are two defect pixels at coordinates (120,430) and (182,430)
// Set the y coordinate to 430
CIntegerParameter(nodemap, "BslStaticDefectPixelCorrectionYCoordinate").SetValue(430);
// Select entry X0 and assign the first x coordinate
CEnumParameter(nodemap, "BslStaticDefectPixelCorrectionXSelector").SetValue("X0");
CIntegerParameter(nodemap, "BslStaticDefectPixelCorrectionXCoordinate").SetValue(120);
// Select entry X1 and assign the second x coordinate, which is in the same line
CEnumParameter(nodemap, "BslStaticDefectPixelCorrectionXSelector").SetValue("X1");
CIntegerParameter(nodemap, "BslStaticDefectPixelCorrectionXCoordinate").SetValue(182);
// Save changes to flash memory
CCommandParameter(nodemap, "BslStaticDefectPixelCorrectionSave").Execute();
// Set the defect pixel correction mode to User
camera.Parameters[PLCamera.BslStaticDefectPixelCorrectionMode].SetValue(PLCamera.BslStaticDefectPixelCorrectionMode.User);
// Assume there are two defect pixels at coordinates (120,430) and (182,430)
// Set the y coordinate to 430
camera.Parameters[PLCamera.BslStaticDefectPixelCorrectionYCoordinate].SetValue(430);
// Select entry X0 and assign the first x coordinate
camera.Parameters[PLCamera.BslStaticDefectPixelCorrectionXSelector].SetValue(PLCamera.BslStaticDefectPixelCorrectionXSelector.X0);
camera.Parameters[PLCamera.BslStaticDefectPixelCorrectionXCoordinate].SetValue(120);
// Select entry X1 and assign the second x coordinate, which is in the same line
camera.Parameters[PLCamera.BslStaticDefectPixelCorrectionXSelector].SetValue(PLCamera.BslStaticDefectPixelCorrectionXSelector.X1);
camera.Parameters[PLCamera.BslStaticDefectPixelCorrectionXCoordinate].SetValue(182);
// Save changes to flash memory
camera.Parameters[PLCamera.BslStaticDefectPixelCorrectionSave].Execute();
/* 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 */
/* Set the defect pixel correction mode to User */
errRes = PylonDeviceFeatureFromString(hdev, "BslStaticDefectPixelCorrectionMode", "User");
CHECK(errRes);
/* Assume there are two defect pixels at coordinates (120,430) and (182,430) */
/* Set the y coordinate to 430 */
errRes = PylonDeviceSetIntegerFeature(hdev, "BslStaticDefectPixelCorrectionYCoordinate", 430);
CHECK(errRes);
/* Select entry X0 and assign the first x coordinate */
errRes = PylonDeviceFeatureFromString(hdev, "BslStaticDefectPixelCorrectionXSelector", "X0");
CHECK(errRes);
errRes = PylonDeviceSetIntegerFeature(hdev, "BslStaticDefectPixelCorrectionXCoordinate", 120);
CHECK(errRes);
/* Select entry X1 and assign the second x coordinate, which is in the same line */
errRes = PylonDeviceFeatureFromString(hdev, "BslStaticDefectPixelCorrectionXSelector", "X1");
CHECK(errRes);
errRes = PylonDeviceSetIntegerFeature(hdev, "BslStaticDefectPixelCorrectionXCoordinate", 182);
CHECK(errRes);
/* Save changes to flash memory */
errRes = PylonDeviceExecuteCommandFeature(hdev, "BslStaticDefectPixelCorrectionSave");
CHECK(errRes);
# Set the defect pixel correction mode to User
camera.BslStaticDefectPixelCorrectionMode.Value = "User"
# Assume there are two defect pixels at coordinates (120,430) and (182,430)
# Set the y coordinate to 430
camera.BslStaticDefectPixelCorrectionYCoordinate.Value = 430
# Select entry X0 and assign the first x coordinate
camera.BslStaticDefectPixelCorrectionXSelector.Value = "X0"
camera.BslStaticDefectPixelCorrectionXCoordinate.Value = 120
# Select entry X1 and assign the second x coordinate, which is in the same line
camera.BslStaticDefectPixelCorrectionXSelector.Value = "X1"
camera.BslStaticDefectPixelCorrectionXCoordinate.Value = 182
# Save changes to flash memory
camera.BslStaticDefectPixelCorrectionSave.Execute()
dart 和 pulse 攝影機#
/* 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 */
/* Disable defect pixel correction */
errRes = PylonDeviceFeatureFromString(hdev, "DefectPixelCorrectionMode", "Off");
CHECK(errRes);
您也可以 use the pylon Viewer 來輕鬆設定參數。