对图像进行滤波处理

40 篇文章 3 订阅
3 篇文章 0 订阅

这里只有代码实现

# 图像去噪平滑滤波
# 使用opencv的自带函数实现,与自编写作比较
# 产生椒盐噪声,高斯噪声等
# 使用中值滤波,平均滤波,高斯滤波,方框滤波

import numpy as np
import cv2
import matplotlib.pyplot as plt
'''
# 加噪声
def noise(img):
    out = img
    rows, cols, chn = img.shape
    for i in range(5000):
        x = np.random.randint(0, rows)
        y = np.random.randint(0, cols)
        out[x, y, :] = 255
    return out
'''
if __name__ == "__main__":
    noise_img = cv2.imread('4.jpg')

    plt.subplot(3, 2, 1)
    plt.imshow(noise_img)
    plt.axis('off')
    plt.title('Original')

    # 均值滤波
    result1 = cv2.blur(noise_img, (5, 5))

    plt.subplot(3, 2, 3)
    plt.imshow(result1)
    plt.axis('off')
    plt.title('mean')

    # 方框滤波
    result2 = cv2.boxFilter(noise_img, -1, (5, 5), normalize=1)

    plt.subplot(3, 2, 4)
    plt.imshow(result2)
    plt.axis('off')
    plt.title('box')

    # 高斯滤波
    result3 = cv2.GaussianBlur(noise_img, (3, 3), 0)

    plt.subplot(3, 2, 5)
    plt.imshow(result3)
    plt.axis('off')
    plt.title('gaussian')

    # 中值滤波
    result4 = cv2.medianBlur(noise_img, 3)

    plt.subplot(3, 2, 6)
    plt.imshow(result4)
    plt.axis('off')
    plt.title('median')

    plt.show()


  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值