在OpenCV里实现全局阈值分割2

接着下来再看THRESH_BINARY_INV类型,它的意思就是与THRESH_BINARY相反,比如大于阈值时THRESH_BINARY设置为最大值,THRESH_BINARY_INV类型设置为0。演示的例子如下:

#python 3.7.4,opencv4.1
#蔡军生 https://blog.csdn.net/caimouse/article/details/51749579
#
import cv2
import numpy as np

#图像数据
src = np.array([[100, 157, 245], [20, 51, 250], [50, 2, 200]], np.uint8)
#阈值处理
retval, dst = cv2.threshold(src, 150, 255, cv2.THRESH_BINARY_INV)

print(src)
print(retval,'\n', dst)

cv2.waitKey(0)
cv2.destroyAllWindows()

你可能感兴趣的:(OpenCV)