初识OpenCV-Python - 007: 平滑图像
2024-09-06 08:17:54
本节内容主要将如何平滑图像。如通过低通道滤波模糊图像。或者自定义滤波处理图像。
import cv2
import numpy as np
from matplotlib import pyplot as plt img = cv2.imread(r'C:\root\learn\python\opencvTest\img\opencvLog.jpg') kernel = np.ones((5,5),np.float32)/25
'''
2D滤波函数。
dst=cv2.filter2D(src,ddepth,kernel[,dst[,anchor[,delta[,borderType]]]])
src:原图像
dst:目标图像,与原图像尺寸和通过数相同
ddepth: 目标图像的所需深度(-1表示输出图像与原图像有相同的深度)
kernel: 卷积核,单通道浮点矩阵;如果要将不同的内核应用于不同的通道,请使用拆分将图像拆分为单独的颜色平面,然后单独处理它们。
anchor: 内核的锚点,指示内核中过滤点的相对位置;锚应位于内核中。默认值(-1,-1)表示锚位于内核中心。
detal: 在将它们存储在dst之前,将可选值添加到已过滤的像素中。类似于偏置。
borderType: 像素外推法。
'''
dst = cv2.filter2D(img,-1,kernel)
'''
均值模糊
'''
blur = cv2.blur(img,(5,5)) '''
高斯模糊
'''
gaussianBlur = cv2.GaussianBlur(img,(5,5),0) '''
中值模糊
'''
median = cv2.medianBlur(img,5)
'''
双边滤波(高斯模糊的高级版本。去噪同时保持边缘锐化)
'''
bilBlur = cv2.bilateralFilter(img,9,75,75)
plt.subplot(161),plt.imshow(img),plt.title('Original')
plt.xticks([]),plt.yticks([])
plt.subplot(162),plt.imshow(dst),plt.title('Averaging')
plt.xticks([]),plt.yticks([])
plt.subplot(163),plt.imshow(blur),plt.title('Blur')
plt.xticks([]),plt.yticks([])
plt.subplot(164),plt.imshow(gaussianBlur),plt.title('GaussianBlur')
plt.xticks([]),plt.yticks([])
plt.subplot(165),plt.imshow(median),plt.title('median')
plt.xticks([]),plt.yticks([])
plt.subplot(166),plt.imshow(bilBlur),plt.title('bilBlur')
plt.xticks([]),plt.yticks([])
plt.show() 图像结果:
最新文章
- BizTalk动手实验(一)安装BizTalk Server 2010开发环境
- ServletConfig对象和它在开发中的应用场
- Angular开发Tips
- TYVJ P1034 尼克的任务 Label:倒推dp
- AutoIt实现selenium上传文件
- c# access插入null值
- C++ static_cast dynamic_cast reinterpret_cast const_cast转换
- 对TCP说三道四(三次握手)
- ASP.NET - 匹配标签中的内容
- 于ios7在遇到一些发展deprecated问题
- awk中{print $1}什么意思
- bootstrap 一个简单的登陆页面
- Python 函数调用&;定义函数&;函数参数
- BZOJ5210 最大连通子块和 【树链剖分】【堆】【动态DP】
- [Centos7]无法访问配置好的nginx
- PHPstorm破解方法及xdebug的断点调试
- 维护贴--验证可用--mysql给root开启远程访问权限,修改root密码(转)
- 咏南中间件开始支持redis client接口调用
- 子查询优化--explain与profiling分析语句
- 补课:PageRank