python实现均值滤波_均值滤波、高斯滤波python实现

这篇博客介绍了如何使用Python实现图像处理中的均值滤波和高斯滤波。通过定义`image_convolution`函数进行卷积操作,`mean_mask`函数生成均值滤波器,以及`gauss_mask`函数生成高斯滤波器。代码中还展示了读取图像、调整图像大小,并应用滤波器进行处理的实例。
摘要由CSDN通过智能技术生成

首先编写卷积代码

保证可以实现各种size滤波

def image_convolution(image,kernel):

[img_height,img_width] = image.shape

[kernel_height,kernel_width] = kernel.shape

expand_width = int((kernel_width - 1)/2)

expand_height = int((kernel_height - 1)/2)

con_height = int(img_height + expand_height*2)

con_width = int(img_width + expand_width*2)

#给结果图像、用于卷积处理的矩阵创建空间

result_image = np.zeros(image.shape)

con_image = np.zeros((con_height, con_width))

#填入图片

con_image[expand_height:expand_height+img_height, expand_width:expand_width+img_width]=image[ : , :]

#对每个像素点进行处理

for i in range(expand_height,expand_height+img_height):

for j in range(expand_width,expand_width+img_width):

result_image[i-expand_height][j-expand_width] = int(np.sum(con_image[i-expand_height:i+expand_h

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值