一起养成写作习惯!这是我参与「掘金日新计划 · 4 月更文挑战」的第14天,点击查看活动详情。
🎉 声明: 作为全网 AI 领域 干货最多的博主之一,❤️ 不负光阴不负卿 ❤️
-
🍊 👋 Follow me 👋,一起 Get 更多有趣 AI 🚀 🚀
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
代码运行
2D Convolution ( Image Filtering )
认识模糊(卷积)核
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()
Image Blurring (Image Smoothing)
- 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()
-
Gaussian Blurring 【高斯模糊】
Gaussian blurring is highly effective in removing Gaussian noise from an image. 代码上,替换模糊函数即可,其它没差;
blur = cv.GaussianBlur(img,(5,5),0)
- Median Blurring 【中心值 [ 中位数 ] 模糊】
blur = cv.medianBlur(img,5)
- Bilateral Filtering 【 双边滤波 】
双边滤波在空间中也采用高斯滤波器,但是又有一个高斯滤波器,它是像素差的函数。空间的高斯函数可确保只考虑附近的像素进行模糊处理,而强度差的高斯函数可确保仅考虑强度与中心像素相似的像素进行模糊处理。由于边缘处的像素强度变化较大,因此可以保留边缘。
blur = cv.bilateralFilter(img,9,75,75)
博主简介:软件工程硕士、已毕业、马上 10w 读者 粉丝
- 🍊 计算机视觉:超分重建、图像修复、目标检测、风格迁移 等领域 稍有所学
- 🍊 AI 工程化:Ncnn、MNN、TensorRT 正在 学习
- 🍊 C++、Python、Java 略懂一二
- 🍊 👋 Follow me 👋,一起 Get 更多有趣 AI、实战博文教程、冲冲冲 🚀 🚀
喜欢请关注 墨理学AI 及其 同名 公众号 墨理学AI
取经路上,让墨理学AI 陪你畅享更多有趣AI