Defect Pixel Correction#
在擷取的影像中,即使使用均勻的光源,某些像素看起來可能仍比其餘像素明顯更亮或更暗。此問題是由個別像素的靈敏度差異所引起,而這些差異又是由製造公差所造成。
使用功能#
此功能的實作方式會因相機而異:
ace 2 R/X、boost R 和 dart M 相機#
Basler ace 2 R、ace 2 X、boost R 與 dart M 相機支援 static defect pixel correction。此校正根據儲存在相機上且包含不良像素座標清單的檔案。
「Static」表示校正程序一律使用相同指定的壞點座標。在影像擷取期間,會根據其相鄰像素的強度值來取代精確這些像素的強度值。
下列不良像素校正檔案可儲存於相機上:
- Factory file: 包含在相機生產期間偵測到的壞點座標。
- User file:包含使用者定義的座標。您可以將此檔案上傳至相機。這可讓您定義隨著時間可能出現的新壞點。
資訊
Basler ace 2 X 相機也支援 dynamic pixel defect correction。如需詳細資訊,請參閱 Pixel Correction Beyond。
使用 pylon Viewer 校正缺陷像素#
→ 請參閱 Static Defect Pixel Correction (pylon Viewer)。
使用 pylon API 校正缺陷像素#
設定 Static Defect Pixel Correction Mode#
若要設定靜態壞點校正模式,請設定 BslStaticDefectPixelCorrectionMode 參數設定為以下值之一:
Factory(預設):靜態不良像素校正的基礎為儲存在 原廠 校正檔案中的壞點。User:靜態不良像素校正的基礎為儲存在 使用者 校正檔案中的壞點。
請注意,透過 pylon API 設定此模式時, 僅 會使用使用者定義的像素。當透過 User incl. Factory 校正模式設定 pylon Viewer時,除了儲存在原廠檔案中的像素之外,還會使用使用者定義的像素。Off:相機 不 執行靜態不良像素校正。
上傳 User Defect Pixel Correction File#
在上傳使用者壞點校正檔案之前,請確保該檔案符合下列檔案格式:
檔案必須以包含四個值為 0 之位元組的 4 位元組標頭開頭。在標頭之後,檔案必須包含壞點項目 (最多可指定 4096 個壞點)。每個項目由 32 位元組成,其順序如下:14 位元 y 座標、14 位元 x 座標、4 位元類型
範例:缺陷像素條目,座標為 x = 1 和 y = 2
若要使用 pylon Viewer 上傳使用者缺陷像素校正檔案:
- 在 pylon Viewer 的 Camera 選單中,按一下 File Access。
- 在 Camera File 下拉式方塊中,選取 User Defect Pixel Correction。
如果沒有 User Defect Pixel Correction 條目,表示您的相機不支援上傳校正檔案。 - 按一下 Upload 並巡覽至您要上傳的檔案。
- 按一下 Open。
若要在上傳後套用使用者缺陷像素校正檔案,請確定 BslStaticDefectPixelCorrectionMode 參數設為 User 並執行 BslStaticDefectPixelCorrectionReload 指令。
下載缺陷像素校正檔案#
如果您想要將自己量測到的缺陷像素新增至下載的檔案中,下載缺陷像素校正檔案(例如原廠校正檔案)可能會很有幫助。您可以將完整的缺陷像素條目清單儲存至新的使用者校正檔案中。
若要使用 pylon Viewer 下載缺陷像素校正檔案:
- 在 pylon Viewer 的 Camera 選單中,按一下 File Access。
- 在 Camera File 下拉式方塊中,根據您要下載的檔案選取 Static Factory Defect Pixel Correction 或 Static User Defect Pixel Correction。
如果沒有適當的條目,表示您的相機不支援下載檔案。 - 按一下 Download,巡覽至您要儲存檔案的目錄,然後輸入所需的檔案名稱。
- 按一下 Open。
靜態缺陷像素校正檔案狀態#
當 StaticDefectPixelCorrectionFileStatus 參數可以接受下列值:
FileStatusUnknown:缺陷像素校正檔案的狀態未知。請擷取影像以變更檔案狀態。FileOk:缺陷像素校正檔案有效。FileNotFound:找不到缺陷像素校正檔案。該檔案從未上傳或已被刪除。FileEmpty:缺陷像素校正檔案沒有任何條目。檔案標頭有效,但檔案未包含任何缺陷像素。缺陷像素校正程序已中止。InvalidHeader:缺陷像素校正檔案標頭無效。檔案必須具有 4 位元組的檔案標頭。InvalidSize:缺陷像素校正檔案大小無效。缺陷像素的最大數量不得超過 4096。InvalidSorting:缺陷像素校正檔案中的條目排序無效。缺陷像素校正程序已中止。InvalidFileEntry:缺陷像素校正檔案中至少有一個條目的大小無效。缺陷像素校正程序已中止。InvalidClustering:找到無效的群集。同一列中有三個或更多相鄰像素會被視為無效群集。其他缺陷像素之間的任何缺陷像素將無法進行校正。
缺陷像素校正檔案可以包含的最大缺陷像素數量。若要取得此數量,請取得以下項目的數值 BslStaticDefectPixelCorrectionMaxDefects 參數中選擇性地指定 HTML 記錄檔 (*.html) 的路徑與檔名。
boost V 相機#
Basler boost V 相機支援 static defect pixel correction。此校正是根據儲存在相機上且包含缺陷像素座標清單的檔案進行的。
「Static」表示校正程序一律使用相同指定的壞點座標。在影像擷取期間,會根據其相鄰像素的強度值來取代精確這些像素的強度值。
執行 Defect Pixel Correction#
資訊
pylon Viewer 內建的 Static Defect Pixel Correction 功能不支援 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將所有修正的像素設定為完全白色。這有助於尋找影像中正在被修正的像素。
移除缺陷像素座標#
原廠檔案中的像素座標無法移除。
不過,您可以移除自訂壞點座標,也就是在「User」修正模式中輸入的座標(請參閱上方)。若要這樣做:
-
如果您想要移除單個自訂壞點座標:
- 將相機中的
BslStaticDefectPixelCorrectionYCoordinate參數設定為 y 壞點的座標。 - 將相機中的
BslStaticDefectPixelCorrectionXSelector參數設定為包含壞點 x 座標的項目,例如X0. - 將相機中的
BslStaticDefectPixelCorrectionXCoordinate參數設為 0xFFFF。 - 執行
BslStaticDefectPixelCorrectionSave指令以將變更儲存至快閃記憶體。
- 將相機中的
-
如果您想要移除所有自訂壞點座標:
- 執行
BslStaticDefectPixelCorrectionClearAll指令。這會將所有BslStaticDefectPixelCorrectionXCoordinate參數值設為 0xFFFF。 - 執行
BslStaticDefectPixelCorrectionSave指令以將變更儲存至快閃記憶體。
- 執行
dart 與 pulse 相機#
Basler dart 和 pulse 相機可以執行兩種類型的像素修正:
- 靜態像素修正會修正強度值顯著低於其相鄰像素的像素,包括完全黑色的像素。
- 動態像素修正會修正強度值顯著高於其相鄰像素的像素,包括完全白色的像素。內部閾值定義了何時將像素偵測為「熱像素」。「動態」表示壞點修正會針對每個擷取的影像分別計算。
設定缺陷像素校正模式#
若要設定 Defect Pixel Correction 模式,請將 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 來輕鬆設定參數。