美文网首页
opencv python版-lesson 14

opencv python版-lesson 14

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

二值化

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

img=cv2.imread('opencv.jpg',0)

ret1,th1=cv2.threshold(img,127,255,cv2.THRESH_BINARY)

ret2,th2=cv2.threshold(img,127,255,cv2.THRESH_BINARY+cv2.THRESH_OTSU)

blur=cv2.GaussianBlur(img,(5,5),0)

ret3,th3=cv2.threshold(blur,0,255,cv2.THRESH_BINARY+cv2.THRESH_OTSU)

image=[img,0,th1,
        img,0,th2,
        blur,0,th3]
titles=[1,2,3,4,5,6,7,8,9]
for i in range(3):
    mp.subplot(3,3,i*3+1),mp.imshow(image[i*3],'gray')
    mp.title(titles[i*3]),mp.xticks([]),mp.yticks([])
    mp.subplot(3,3,i*3+2),mp.hist(image[i*3].ravel(),256)
    mp.title(titles[i*3+1]),mp.xticks([]),mp.yticks([])
    mp.subplot(3,3,i*3+3),mp.imshow(image[i*3+2],'gray')
    mp.title(titles[i*3+2]),mp.xticks([]),mp.yticks([])
mp.show()

相关文章

网友评论

      本文标题:opencv python版-lesson 14

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