本文主要是介绍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)
这篇关于OpenCV Threshold ( Python , C++ )的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!