使用 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)
輸出
廣告