1.高斯模糊化
# -*- coding: utf-8 -*- """ Created on Wed Dec 5 14:57:40 2018 @author: 1 """ #import numpy as np import cv2 #import matplotlib.pyplot as plt img = cv2.imread('WIN_20190110_16_56_25_Pro.jpg') img_ = cv2.GaussianBlur(img, ksize=(29,29), sigmaX=0, sigmaY=0) cv2.imshow('Source image',img) cv2.imshow('blur image',img_) cv2.waitKey()
2.二值化
# -*- coding: utf-8 -*- """ Created on Wed Nov 21 14:52:55 2018 @author: 1 """ import cv2 import matplotlib.pyplot as plt img = cv2.imread('YCbCr.jpg',0) #直接读为灰度图像 #简单滤波 ret1,th1 = cv2.threshold(img,10,255,cv2.THRESH_BINARY) #Otsu 滤波 ret2,th2 = cv2.threshold(img,0,255,cv2.THRESH_BINARY+cv2.THRESH_OTSU) th3 = cv2.adaptiveThreshold(img,255,cv2.ADAPTIVE_THRESH_MEAN_C,cv2.THRESH_BINARY,11,2) ret, dst = cv2.threshold(img, 127, 255, cv2.THRESH_BINARY) cv2.imshow("ss",th1) ##cv2.imwrite("aaa.jpg", th3) cv2.imwrite("Binary_5.jpg",th1) #print(ret2) #plt.figure() #plt.subplot(221),plt.imshow(img,'gray') #plt.subplot(222),plt.hist(img.ravel(),256)#.ravel方法将矩阵转化为一维 #plt.subplot(223),plt.imshow(th1,'gray') #plt.subplot(224),plt.imshow(th3,'gray') #img=cv2.imread('1111.jpg') #cv2.imshow("1111.jpg",img)