OPEN CV中图像的滤波操作(图像的平滑处理,去除噪声等)

1.原图素材:

OPEN CV中图像的滤波操作(图像的平滑处理,去除噪声等)_第1张图片

import cv2
import matplotlib.pyplot as plt
import  numpy as np
def cv_show(name,img):
    cv2.imshow(name,img)
    cv2.waitKey(0)
    cv2.destroyAllWindows()


if __name__ == "__main__":
    # img = cv2.imread(r'E:\iu.png')  # 读取方式默认为BGR
    # cv_show('image',img)
    #灰度图读取
    #img2 = cv2.imread(r'E:\iu.png',cv2.IMREAD_GRAYSCALE)#灰度图
    img1 = cv2.imread(r'E:\imageonline-co-noisedimage.png')
    # cv_show('image2',img1)
    # print(img.size)#像素点个数
    # print(img.shape)  #图像维度
    # scharrx = cv2.Scharr(img2,cv2.CV_64F,0,1)#水平Gx
    # scharrx = cv2.convertScaleAbs(scharrx)
    # scharry = cv2.Scharr(img2, cv2.CV_64F, 1, 0)  # 垂直Gy
    # scharry = cv2.convertScaleAbs(scharry)
    # cv_show('scharr',cv2.addWeighted(scharrx,0.5,scharry,0.5,0))#相加两者权重各位0.5,0是偏置项
    # Laplacian = cv2.Laplacian(img2,cv2.CV_64F)
    # Laplacian = cv2.convertScaleAbs(Laplacian)
    # cv_show('pre', img1)
    # 均值滤波
    blur = cv2.blur(img1,(3,3))
    # cv_show("blur",blur)
    #中值滤波
    median = cv2.medianBlur(img1,5)
    # cv_show('pre', median)
    #方框滤波
    box = cv2.boxFilter(img1,-1,(3,3),normalize = True)
    # cv_show('pre', box)
    #高斯滤波
    aussian = cv2.GaussianBlur(img1,(5,5),1)
    # cv_show("gaosi",aussian)
    res = np.hstack((blur,median,box,aussian))
    cv_show("duibi",res)

 结果:

OPEN CV中图像的滤波操作(图像的平滑处理,去除噪声等)_第2张图片

 

你可能感兴趣的:(图像处理,计算机视觉,人工智能)