zhiqingstudy

Be a young person with knowledge and content

The function of filtering is to get another image through a filter, where the filter is also called convolution kernel, and the filtering process is called convolution.
Several basic concepts of convolution:
  1. Size of convolution kernel: The convolution kernel is generally odd, such as 3 * 3, 5 * 5, 7 * 7, etc. In depth learning, the larger the convolution kernel is, the more information you can see, the better the extracted features are, and the greater the amount of computation is.
  2. Anchor point: in short, it is the center of the picture
  3. Boundary expansion: when the convolution kernel is greater than 1 and no boundary expansion is carried out, the output size will be reduced accordingly. When the convolution kernel performs boundary expansion in a standard way, the space size of the output data will be equal to that of the input data.
  4. step
Output picture size calculation formula:
N=(W-F+2P)/S+1
N is the output image size
W is the size of the original image; F is the size of convolution kernel; P is the extended dimension
S is the step size

Concept of low-pass filter and high pass filter
Low pass filtering refers to passing below a certain threshold. Low pass filtering can remove noise or smooth the image.
High pass filtering means that those above a certain threshold can pass. High pass filtering can help find image edges.
Image convolution api: filter2D (src, ddepth, kernel, anchor, delta, borderType)
Src: which image to convolve
Ddepth: the bit depth of the image after convolution (generally set to - 1, the bit depth of the original image is what, and the new image generated is what)
Kernel: convolution kernel
Anchor: anchor (it can be left unset, and the anchor will be found according to the convolution kernel)
Delta: add a delta value to the element after convolution. If you want to add a delta value, set it here
BorderType: boundary type

Square wave filtering and mean filtering
If we create our own convolution kernel every time, the process is still very troublesome. Many filters are fixed, such as square box filtering and mean filtering. Their cores are fixed. Opencv provides us with apis for these filters that we just need to call.
Square box filtering formula:
How to use opencv image filtering? Opencv image mean filtering method

For different cases, a takes different values. Square box filtering has a parameter normalize.
normalize=true时,a=1/(W*H),就是一个均值滤波
normalize=false时,a=1。
当normalize==true时,方盒滤波==均值滤波。

Box filter api: boxFilter (src, ddpth, ksize, anchor, normalize, borderType)
Src: specific image to be convolved
Ddpth: Bit depth of output image
Ksize: the size of the convolution kernel
Anchor: anchor point, the default value is (- 1, - 1), the center point of the core, so there is no special setting, just keep the default
BorderType: boundary type of output

Average filter api: blur (src, ksize, anchor, borderType)
import cv2
import numpy as np

# 导入一张图片
img=cv2.imread('你的图片')
# 图片卷积,创造卷积核
dst=cv2.filter2D(img,-1,np.ones((5,5),np.float32)/25)
# 均值滤波,5*5的均值滤波
dst1=cv2.blur(img,(5,5))
# 图片展示
cv2.imshow('img',img)
cv2.imshow('dst',dst)
cv2.imshow('dst1',dst1)
cv2.waitKey(0)
comment
head sculpture
Code:
Related

Why you shouldn't stay at a job for more than 2 years?

3 harsh facts long-distance relationships

how to keep your girlfriend interested in a long-distance relationship




Unless otherwise specified, all content on this website is original. If the reprinted content infringes on your rights, please contact the administrator to delete it
Contact Email:2380712278@qq.com

Filing number:皖ICP备19012824号