码迷,mamicode.com
首页 > 编程语言 > 详细

OpenCV&&python_图像平滑(Smoothing Images)

时间:2017-05-28 22:35:55      阅读:455      评论:0      收藏:0      [点我收藏+]

标签:ide   sim   name   osi   put   ash   ges   operation   optional   

  • Goals

 

  1. 学习用不同低通滤波方法模糊图像(Blur imagess with various low pass filter)
  2. 用用定制的滤波器处理图像(Apply custom-made filters to images (2D convolution))

高通滤波与低通滤波

 

images can be filtered with various low-pass filters (LPF), high-pass filters (HPF), etc.  A LPF helps in removing noise, or blurring the image. A HPF filters helps in finding edges in an image.


cv2.filter2D() 

OpenCV  provides a function cv2.filter2D() to convolve卷积 a kernel(核) with an image. 例如:

定义一个5x5 averaging filter kernel

技术分享

 

 

 直接上代码:

import cv2
import numpy as np
from matplotlib import pyplot as plt
#读图像
img = cv2.imread(‘text.jpg‘)
#核的定义
kernel = np.ones((5,5),np.float32)/25
dst = cv2.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()

 结果展示:

技术分享

 

 


 

注释:

技术分享

 

 技术分享

Python: cv.Filter2D(src, dst, kernel, anchor=(-1, -1)

  • src – input image.
  • dst – output image of the same size and the same number of channels as src.
  • kernel – convolution kernel (or rather a correlation kernel), a single-channel floating point matrix; if you want to apply different kernels to different channels, split the image into separate color planes using split() and process them individually.
  • anchor – anchor of the kernel that indicates the relative position of a filtered point within the kernel; the anchor should lie within the kernel; default value (-1,-1) means that the anchor is at the kernel center.
  • delta – optional value added to the filtered pixels before storing them in dst.
  • borderType – pixel extrapolation method (see borderInterpolate() for details).

 

 

OpenCV&&python_图像平滑(Smoothing Images)

标签:ide   sim   name   osi   put   ash   ges   operation   optional   

原文地址:http://www.cnblogs.com/lwbjyp/p/6916680.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!