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

Brightness and Contrast (dart E)#

「Brightness and Contrast 」相機功能可讓您調整影像的色調值。

亮度與對比度總是作為共同的數學亮度/對比度函數的一部分,一併進行處理。

使用功能#

調整對比度#

若要調整對比度,請為 BslContrast 參數。該參數的數值範圍為 -1 至 1。預設情況下,該參數設定為 0,這表示對比度維持不變。

調整亮度#

若要調整亮度,請輸入 BslBrightness 參數。該參數的數值範圍為 -1 至 1。預設情況下,此參數設定為 0,這表示亮度保持不變。

運作原理#

對比度#

調整對比度會改變影像中明暗區域之間的差異程度。對比度設定得越高,這種差異就越明顯。

這台相機採用S 型曲線函數來調整對比度。

這能讓您在維持影像動態範圍的同時,提升視覺上的對比度。

對比度調得越高,該函數的圖形就越趨近於 S 形:

對比度 = 0.3、亮度 = 0、S 型曲線對比度模式

對比度 = 0.5、亮度 = 0、S 型曲線對比度模式

上圖顯示,在 S 曲線模式下提高對比度會產生以下效果:

  • S 型曲線在起點和終點附近較為平緩,而在中間部分則較為陡峭。因此,影像中亮部與暗部的對比度會降低,而中間調的對比度則會增加。
  • 輸入的低像素值會被降低,而高像素值則會被提高。因此,影像中極暗與極亮的區域會被壓縮,進而進一步提升視覺上的對比度。
  • 由於曲線總是從 (0,0) 開始,並以 (Xmax,Ymax) 結束,因此影像的動態範圍得以保留。

在 S 曲線模式下,若將對比度設定低於 0,將會產生反向的 S 曲線,並產生相反的效果。

亮度#

調整亮度可透過增加或減少影像的色調值,來使影像變亮或變暗。

調整亮度會移動「亮度/對比度」功能的旋轉點:

  • 提高亮度會將旋轉點向左上方移動。這表示影像會顯得更亮。
  • 降低亮度會將旋轉點移至右下角。這表示影像會顯得較暗。

對比度 = 0.3、亮度 = 0、S 型曲線對比度模式

對比度 = 0.3、亮度 = 0.3、S 曲線對比度模式

範例程式碼#

// Set the Brightness parameter to 0.5
camera.BslBrightness.SetValue(0.5);
// Set the Contrast parameter to 1.2
camera.BslContrast.SetValue(1.2);
INodeMap& nodemap = camera.GetNodeMap();
// Set the Brightness parameter to 0.5
CFloatParameter(nodemap, "BslBrightness").SetValue(0.5);
// Set the Contrast parameter to 1.2
CFloatParameter(nodemap, "BslContrast").SetValue(1.2);
// Set the Brightness parameter to 0.5
camera.Parameters[PLCamera.BslBrightness].SetValue(0.5);
// Set the Contrast parameter to 1.2
camera.Parameters[PLCamera.BslContrast].SetValue(1.2);
/* 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 Brightness parameter to 0.5 */
errRes = PylonDeviceSetFloatFeature(hdev, "BslBrightness", 0.5);
CHECK(errRes);
/* Set the Contrast parameter to 1.2 */
errRes = PylonDeviceSetFloatFeature(hdev, "BslContrast", 1.2);
CHECK(errRes);
# Set the Brightness parameter to 0.5
camera.BslBrightness.Value = 0.5
# Set the Contrast parameter to 1.2
camera.BslContrast.Value = 1.2
/* 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 Brightness parameter to 0.5 */
errRes = PylonDeviceSetFloatFeature(hdev, "BslBrightness", 0.5);
CHECK(errRes);
/* Set the Contrast parameter to 1.2 */
errRes = PylonDeviceSetFloatFeature(hdev, "BslContrast", 1.2);
CHECK(errRes);

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