OpenCV Threshold ( Python , C++ )

本系列主要为learn opencv的翻译和学习,整理。
参考:https://www.learnopencv.com/opencv-threshold-python-cpp/

——————————————————————————————————————

阈值分割:

1、Binary Threshold
原理:
if src(x,y) > thresh
dst(x,y) = maxValue
else
dst(x,y) = 0

函数:
cv2.threshold(src, thresh, maxValue, cv2.THRESH_BINARY);

python 代码
import cv2
src = cv2.imread(“threshold.png”, cv2.IMREAD_GRAYSCALE)
thresh = 5
maxValue = 255
th, dst = cv2.threshold(src, thresh, maxValue, cv2.THRESH_BINARY);

2、 Inverse Binary Threshold
原理:
if src(x,y) > thresh
dst(x,y) = 0
else
dst(x,y) = maxValue
函数:
cv2.threshold(src, thresh, maxValue, cv2.THRESH_BINARY_INV)

3、Truncate Thresholding
原理:
if src(x,y) > thresh
dst(x,y) = thresh
else
dst(x,y) =src(x,y)
函数:
cv2.threshold(src, thresh, maxValue, cv2.THRESH_TRUNC)

4、Threshold to Zero
原理:
if src(x,y) > thresh
dst(x,y) = src(x,y)
else
dst(x,y) =0
函数:
cv2.threshold(src, thresh, maxValue, cv2.THRESH_TOZERO)

5、Inverted Threshold to Zero
原理:
if src(x,y) > thresh
dst(x,y) = 0
else
dst(x,y) =src(x,y)
函数:
cv2.threshold(src, thresh, maxValue, cv2.THRESH_TOZERO_INV)

猜你喜欢

转载自blog.csdn.net/sangky/article/details/83210889