本节内容主要将如何平滑图像。如通过低通道滤波模糊图像。或者自定义滤波处理图像。

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() 图像结果:
 

最新文章

  1. BizTalk动手实验(一)安装BizTalk Server 2010开发环境
  2. ServletConfig对象和它在开发中的应用场
  3. Angular开发Tips
  4. TYVJ P1034 尼克的任务 Label:倒推dp
  5. AutoIt实现selenium上传文件
  6. c# access插入null值
  7. C++ static_cast dynamic_cast reinterpret_cast const_cast转换
  8. 对TCP说三道四(三次握手)
  9. ASP.NET - 匹配标签中的内容
  10. 于ios7在遇到一些发展deprecated问题
  11. awk中{print $1}什么意思
  12. bootstrap 一个简单的登陆页面
  13. Python 函数调用&定义函数&函数参数
  14. BZOJ5210 最大连通子块和 【树链剖分】【堆】【动态DP】
  15. [Centos7]无法访问配置好的nginx
  16. PHPstorm破解方法及xdebug的断点调试
  17. 维护贴--验证可用--mysql给root开启远程访问权限,修改root密码(转)
  18. 咏南中间件开始支持redis client接口调用
  19. 子查询优化--explain与profiling分析语句
  20. 补课:PageRank

热门文章

  1. Spring容器对Bean组件的管理
  2. 整理delphi及整理原则
  3. 39 Ubuntu下配置python的vscode开发环境
  4. Hbase的安装和部署
  5. NX二次开发-UFUN所有对象类型的宏定义
  6. python virtual env 使用 jupyter ipython notebook,舒服了, 工作效率翻倍
  7. Java-Class-I:java.util.Map
  8. 创建第一个spirngmvc小项目
  9. Solrj API读取core 索引库数据
  10. 2018北京网络赛 G The Mole /// 分块暴力 点线距离