美文网首页
opencv python版-lesson 12

opencv python版-lesson 12

作者: writ | 来源:发表于2019-10-15 20:16 被阅读0次

阈值化

import cv2
import numpy as np
import matplotlib.pyplot as mp

img=cv2.imread('opencv.jpg',0)
ret,thresh1=cv2.threshold(img,127,255,cv2.THRESH_BINARY)
ret,thresh2=cv2.threshold(img,127,255,cv2.THRESH_BINARY_INV)
ret,thresh3=cv2.threshold(img,127,255,cv2.THRESH_TRUNC)
ret,thresh4=cv2.threshold(img,127,255,cv2.THRESH_TOZERO)
ret,thresh5=cv2.threshold(img,127,255,cv2.THRESH_TOZERO_INV)


titles = ['original Image', 'binary','BINARY_INV', 'TRUNC','TOZERO','tozero_inv']
images = [img, thresh1, thresh2, thresh3, thresh4, thresh5]

for i in range(6):
    mp.subplot(2,3,i+1),mp.imshow(images[i],'gray')
    mp.title(titles[i])
    mp.xticks([]),mp.yticks([])

mp.show()

相关文章

网友评论

      本文标题:opencv python版-lesson 12

      本文链接:https://www.haomeiwen.com/subject/fdkemctx.html