Mathematical Road-python Calculation (19)-Machine vision-convolution filter

Source: Internet
Author: User

Filter2d

Convolves an image with the kernel.

C + +:   void  filter2d ( inputarray  src , outputarray  DST , int  ddepth , Inputarray kernel , 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, Cvpoint anchor =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'll be the same as src.depth (); The following combinations of src.depth () and ddepth are supported:
    • src.depth ()  = cv_8u ,  ddepth  = -1/cv_16s /cv_32f /cv_64f
    • src.depth ()  = cv_16u /cv_16s ,  ddepth  = -1/cv_32f /cv_64f
    • src.depth ()  = cv_32f ,  ddepth  = -1/cv_32f /cv_64f
    • src.depth () = cv_64f, ddepth = -1/cv_64f

    When ddepth=-1, the output image would 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 for a filtered point within the kernel; The anchor should lie within the kernel; Default value ( -1,-1) means that the anchor are 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 a arbitrary linear filter to an image. In-place operation is supported. When the aperture was partially outside the image, the function interpolates outlier pixel values according to the Specifie d Border mode.

#-*-Coding:utf-8-*-   #卷积滤波 #code:[email protected]import cv2import numpy as npfn= "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 ()

the whole content of this blog is original, if reproduced please indicate the sourcehttp://blog.csdn.net/myhaspl/


Mathematical Road-python Calculation (19)-Machine vision-convolution filter

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.