如何获得2d的高斯核? (opencv) [英] How do I get to show Gaussian Kernel for 2d? (opencv)
问题描述
我正在使用这个:
blur = cv2.GaussianBlur(dst,(5,5),0)
我想以此显示内核矩阵:
And I wanted to show the kernel matrix by this:
print(cv2.getGaussianKernel(ksize=(5,5),sigma=0))
但是我收到类型错误:
TypeError: an integer is required (got type tuple)
如果我只放5,我将得到一个5x1矩阵.模糊内核不是5x5吗?还是我缺少基本的东西?
If I only put 5, I get a 5x1 matrix. Isn't the blur kernel 5x5? Or am I missing on something fundamental?
推荐答案
高斯内核是可分离的.因此,生成的内核是1D. GaussianBlur
函数依次沿每个图像维应用此一维内核.可分离性意味着该过程产生与应用2D卷积(或3D图像的情况下为3D)完全相同的结果.但是工作量大大减少了.对于5x5内核,2D卷积执行25次乘法和加法,可分离实现仅执行5 + 5 = 10.对于更大的内核,收益越来越显着.
The Gaussian kernel is separable. Therefore, the kernel generated is 1D. The GaussianBlur
function applies this 1D kernel along each image dimension in turn. The separability property means that this process yields exactly the same result as applying a 2D convolution (or 3D in case of a 3D image). But the amount of work is strongly reduced. For your 5x5 kernel, the 2D convolution does 25 multiplications and additions, the separable implementation does only 5+5=10. For larger kernels, the gains are increasingly significant.
要查看完整的2D内核,请将GaussianBlur
函数应用于全为零且中间单个像素设置为1的图像.这是与Dirac delta函数等效的离散项,我们可以使用它分析线性时不变函数(==卷积滤波器).
To see the full 2D kernel, apply the GaussianBlur
function to an image that is all zeros and has a single pixel in the middle set to 1. This is the discrete equivalent to the Dirac delta function, which we can use to analyze linear time-invariant functions (==convolution filters).
这篇关于如何获得2d的高斯核? (opencv)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!