使用 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)输出

广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP