图像不同的降采样方式(模糊处理)

本文介绍了OpenCV库中用于图像模糊处理的四种算法:平均模糊、高斯模糊、中值模糊和双边模糊,并提及scipy库中的类似方法。模糊处理常用于边沿检测和去噪声。文章提供了一段实验过程中的批处理代码示例,以实现不同采样数据的获取。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

模糊处理在边沿检测和去噪声方面有较为广泛的应用。OpenCV中提供了4种模糊算法,列举如下:

  • average
  • median
  • gaussian
  • bilateral

 

而scipy中同样有几种方式,其本质上是没区别的。

我们先来看模糊算法的实现:

 

1.average

    import numpy
    import argparse
    import cv2

    image = cv2.imread('1.jpg')
    cv2.imshow("Original", image)

    gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
    cv2.imshow("Gray", gray)


    #[x,y] is the kernel for bluring
    #the large kernel becomes, the more blurred imag will appear
    #hstack is able to stack multiple images together
    #using simple mean to average
    blurred = numpy.hstack([
    cv2.blur(gray, (3,3)),
    cv2.blur(gray, (5,5)),
    cv2.blur(gray, (7,7))])

    #display two images in a figure
    cv2.imshow("Blurring by average", blurred)

    cv2.imwrite("1_blur_by_average.jpg", blurred)


    if(cv2.waitKey(0)==27):
     cv2.destroyAllWindows()

 

2.

Gaussian

import numpy
    import argparse
    import cv2

    image = cv2.imread('1.jpg')
    cv2.imshow("Original", image)

    gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
    cv2.imshow("Gray", gray)


    #[x,y] is the kernel for bluring
    #the large kernel becomes, the more blurred imag will appear
    #hstack is able to stack multiple images together
    #using weighted mean
    #where neighborhood pixels that are closer to the central pixel contribute more "weight" to the average
    blurred = numpy.hstack([
    cv2.GaussianBlur(gray, (3,3), 0),
    cv2.GaussianBlur(gray, (5,5), 0),
    cv2.GaussianBlur(gray, (7,7), 0)])

    #display two images in a figure
    cv2.imshow("Blurring by Gaussian", blurred)

    cv2.imwrite("1_blur_by_Gaussian.jpg", blurred)


    if(cv2.waitKey(0)==27):
     cv2.destroyAllWindows()


3.

median

  import numpy
    import argparse
    import cv2

    image = cv2.imread('1.jpg')
    cv2.imshow("Original", image)

    gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
    cv2.imshow("Gray", gray)


    #[x,y] is the kernel for bluring
    #the large kernel becomes, the more blurred imag will appear
    #hstack is able to stack multiple images together
    #the central pixel is replaced with the median of the neighborhood
    #it is the most effective when removing salt-and-pepper noise
    blurred &#
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值