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)
# 高斯模糊

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





