使用 OpenCV 对图像执行截断阈值化
在本程序中,我们将使用 openCV 对图像执行截断阈值化。阈值化是一个处理,每个像素的值都将相对于阈值而改变。
如果像素小于阈值就赋予它特定值,如果像素大于阈值就赋予它其他值。在截断阈值化中,大于阈值的值被减少到阈值。所有其他像素保持不变。
原始图像

算法
Step 1: Import cv2. Step 2: Define 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_TRUNC)
cv2.imshow('TruncateThresholding', image)输出

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