python OpenCV给图像添加不同种类模糊 | 小白笔记

举报
墨理学AI 发表于 2022/01/10 22:29:53 2022/01/10
【摘要】 Blur images with various low pass filters 总的来看,官方教程虽然是英文,然而很多时候解释的更为清晰,查阅也更为高效,英语好的不要犹豫,直接去查看官...

Blur images with various low pass filters


总的来看,官方教程虽然是英文,然而很多时候解释的更为清晰,查阅也更为高效,英语好的不要犹豫,直接去查看官方教程


环境搭建


conda create -n torch11 python=3.6.9

conda activate torch11

pip install opencv-python

pip install matplotlib 

pip install numpy

  
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

代码运行


2D Convolution ( Image Filtering )

认识模糊(卷积)核

0-0

import numpy as np
import cv2 as cv
from matplotlib import pyplot as plt
img = cv.imread('opencv_logo.png')

kernel = np.ones((5,5),np.float32)/25

dst = cv.filter2D(img,-1,kernel)
plt.subplot(121),plt.imshow(img),plt.title('Original')
plt.xticks([]), plt.yticks([])
plt.subplot(122),plt.imshow(dst),plt.title('Averaging')
plt.xticks([]), plt.yticks([])
plt.show()

  
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13

0-0

Image Blurring (Image Smoothing)

0-1

  • Averaging 【平均模糊】
import cv2 as cv
import numpy as np
from matplotlib import pyplot as plt

img = cv.imread('img/moli.jpg')

blur = cv.blur(img,(5,5))

plt.subplot(121),plt.imshow(img),plt.title('Original')
plt.xticks([]), plt.yticks([])

plt.subplot(122),plt.imshow(blur),plt.title('Blurred')
plt.xticks([]), plt.yticks([])

plt.show()

  
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15

0-2

  • Gaussian Blurring 【高斯模糊】

Gaussian blurring is highly effective in removing Gaussian noise from an image.
代码上,替换模糊函数即可,其它没差;

blur = cv.GaussianBlur(img,(5,5),0)

  
 
  • 1

0-3

  • Median Blurring 【中心值 [ 中位数 ] 模糊】

1-5

blur = cv.medianBlur(img,5)

  
 
  • 1

0-4

  • Bilateral Filtering 【 双边滤波 】

双边滤波在空间中也采用高斯滤波器,但是又有一个高斯滤波器,它是像素差的函数。空间的高斯函数可确保只考虑附近的像素进行模糊处理,而强度差的高斯函数可确保仅考虑强度与中心像素相似的像素进行模糊处理。由于边缘处的像素强度变化较大,因此可以保留边缘。

blur = cv.bilateralFilter(img,9,75,75)

  
 
  • 1

0-5


9-6


文章来源: positive.blog.csdn.net,作者:墨理学AI,版权归原作者所有,如需转载,请联系作者。

原文链接:positive.blog.csdn.net/article/details/116176067

【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。