如何使用OpenCV将偏导数高斯核应用于图像? [英] How to apply a partial derivative Gaussian kernel to an image with OpenCV?
问题描述
我正在尝试从论文中复制结果,在该结果中,它们将图像与高斯核的水平偏导数进行卷积.我还没有找到任何使用OpenCV实现该目标的方法.那可能吗 ?
I'm trying reproduce results from a paper, in which they convolve the image with an horizontal partial derivative of a Gaussian kernel. I haven't found any way to achieve that with OpenCV. Is that possible ?
我是否必须先获得高斯滤波器,然后手动计算偏导数?
Do I have to get Gaussian filter and then compute the partial derivatives by hand ?
推荐答案
OpenCV没有内置函数来计算高斯偏导数.但是您可以使用 cv::getGaussianKernel
和 cv::filter2D
这样做.
OpenCV doesn't have built-in function to calculate Gaussian partial derivatives. But you may use cv::getGaussianKernel
and cv::filter2D
to do so.
例如:
cv::Mat kernel = cv::getGaussianKernel(3, 0.85, CV_32F);
kernel = kernel.reshape(1, 1);
cv::filter2D(img, img, CV_8U, kernel);
请注意,cv::getGaussianKernel
返回列过滤器,因此您需要reshape
将其水平放置.
Please note that cv::getGaussianKernel
returns column filter, so you need reshape
to make it horizontal.
这篇关于如何使用OpenCV将偏导数高斯核应用于图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!