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

数学之路-python计算实战(19)-机器视觉-卷积滤波

时间:2014-08-29 18:13:58      阅读:255      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   http   color   os   io   strong   ar   

filter2D

Convolves an image with the kernel.

C++: void filter2D(InputArray src, OutputArray dst, int ddepth, InputArraykernel, Point anchor=Point(-1,-1), double delta=0, int borderType=BORDER_DEFAULT )
Python: cv2.filter2D(src, ddepth, kernel[, dst[, anchor[, delta[, borderType]]]]) → dst
C: void cvFilter2D(const CvArr* src, CvArr* dst, const CvMat* kernel, CvPointanchor=cvPoint(-1,-1) )
Python: cv.Filter2D(src, dst, kernel, anchor=(-1, -1)) → None
Parameters:
  • src – input image.
  • dst – output image of the same size and the same number of channels as src.
  • ddepth –
    desired depth of the destination image; if it is negative, it will be the same as src.depth(); the following combinations ofsrc.depth() and ddepth are supported:
    • src.depth() = CV_8Uddepth = -1/CV_16S/CV_32F/CV_64F
    • src.depth() = CV_16U/CV_16Sddepth = -1/CV_32F/CV_64F
    • src.depth() = CV_32Fddepth = -1/CV_32F/CV_64F
    • src.depth() = CV_64Fddepth = -1/CV_64F

    when ddepth=-1, the output image will have the same depth as the source.

  • 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 (seeborderInterpolate() for details).

The function applies an arbitrary linear filter to an image. In-place operation is supported. When the aperture is partially outside the image, the function interpolates outlier pixel values according to the specified border mode.

# -*- coding: utf-8 -*-   
#卷积滤波
#code:myhaspl@myhaspl.com
import cv2
import numpy as np
fn="test2.jpg"
myimg=cv2.imread(fn)
img=cv2.cvtColor(myimg,cv2.COLOR_BGR2GRAY)
myh=np.array([[0,1,0],[1,-4,1],[0,1,0]])
jgimg=cv2.filter2D(img,-1,myh)
cv2.imshow(‘src‘,img)
cv2.imshow(‘dst‘,jgimg)
cv2.waitKey()
cv2.destroyAllWindows()

本博客全部内容是原创,假设转载请注明来源

http://blog.csdn.net/myhaspl/


bubuko.com,布布扣

数学之路-python计算实战(19)-机器视觉-卷积滤波

标签:des   style   blog   http   color   os   io   strong   ar   

原文地址:http://www.cnblogs.com/mengfanrong/p/3945426.html

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