使用 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) cv2.imshow('ZeroThresholding', image)
輸出
廣告