python实现对图片进行均值滤波、中值滤波、高斯滤波处理及其原理和特点

本文介绍了三种常见的图像滤波技术:高斯滤波、均值滤波和中值滤波。通过Python代码展示了如何使用PIL和OpenCV库实现这些滤波操作,分别用于图像平滑和去噪。高斯滤波能较好地保留图像特征,均值滤波可能导致图像模糊,而中值滤波在去除脉冲噪声的同时保护图像边缘。

1.高斯滤波

        1)原理:对图像邻域内像素进行平滑时,邻域内不同位置的像素被赋予不同的权值。

        2)特点:对图像进行平滑的同时,同时能够更多的保留图像的总体灰度分布特征。

        3)代码

import os
from PIL import Image, ImageFilter


class MyGaussianBlur(ImageFilter.Filter):
    name = "GaussianBlur"

    def __init__(self, radius=2, bounds=None):
        self.radius = radius
        self.bounds = bounds

    def filter(self, image):
        if self.bounds:
            clips = image.crop(self.bounds).gaussian_blur(self.radius)
            image.paste(clips, self.bounds)
            return image
        else:
            return image.gaussian_blur(self.radius)


# 源目录
input_Path = 'D:/python/bitters/bitter/'
# 输出目录
Output_Path = 'D:/python/bitters/gaosi_bitter/'


def processImage(filesoure, destsoure, name, imgtype):
    imgtype = 'jpeg' if imgtype == '.jpg' else 'png'

    # 打开图片
    im = Image.open(filesoure + name)
    # 高斯模糊
  
评论 2
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值