# -*- coding: utf-8 -*-
import cv2 as cv
import numpy as np

def display_img(img):
cv.imshow('image',img)
cv.waitKey(0)
cv.destroyAllWindows()

def average_(filepath):#均值滤波,适用于去除通过扫描得到的图像中的颗粒噪声
img = cv.imread(filepath)
blur = cv.blur(img,(3,3))
#display_img(blur)
return blur

def box_(filepath):#方块滤波通过“修正”重建块的像素值,尤其是边间附近的像素值,从而达到消除编解码算法带来的方块效应的目的
img = cv.imread(filepath)
box = cv.boxFilter(img,-1,(3,3),normalize=True)
#display_img(box)
return box

def gauss_(filepath):# 高斯滤波器是一种线性滤波器,能够有效的抑制噪声
img = cv.imread(filepath)
gauss = cv.GaussianBlur(img,(5,5),1)
#display_img(gauss)
return gauss
def median_(filepath):#中值滤波对于滤除脉冲干扰及图像扫描噪声最为有效
img = cv.imread(filepath)
median = cv.medianBlur(img,5)
#display_img(median)
return median

def main():
filepath ="lenda.png"
average = average_(filepath)
box = box_(filepath)
gauss = gauss_(filepath)
median = median_(filepath)
res = np.hstack((average,box,gauss,median))
display_img(res)

main()

均值滤波, 适用于去除通过扫描得到的图像中的颗粒噪声

方块滤波,通过“修正”重建块的像素值,尤其是边间附近的像素值,从而达到消除编解码算法带来的方块效应的目的

高斯滤波,是一种线性滤波器,能够有效的抑制噪声

中值滤波,对于滤除脉冲干扰及图像扫描噪声最为有效

常用滤波器_编解码