使用 OpenCV 對影像執行反向零閾值


在本程式中,我們將使用 OpenCV 對影像執行反向零閾值。閾值化是一種根據閾值更改每個畫素值的過程。如果畫素小於閾值,則賦予其某個值,如果大於閾值,則賦予其另一個值。在反向零閾值中,強度值大於閾值的畫素設定為 0。

原始影像

演算法

Step 1: Import cv2.
Step 2: Define the threshold and max_val.
Step 3: Pass these parameters in the cv2.threshold value and specify the type of thresholding you want to do.
Step 4: Display the output.

示例程式碼

import cv2

image = cv2.imread('testimage.jpg')
threshold_value = 120
max_val = 255
ret, image = cv2.threshold(image, threshold_value, max_val, cv2.THRESH_TOZERO_INV)
cv2.imshow('InverseZeroThresholding', image)

輸出

更新日期:2021-03-17

245 次瀏覽

開啟您的職業生涯

完成此課程以獲得認證

開始學習
廣告