How to apply a partial derivative Gaussian kernel to an image with OpenCV?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-12 17:15:22

问题


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 ?


回答1:


OpenCV doesn't have built-in function to calculate Gaussian partial derivatives. But you may use cv::getGaussianKernel and cv::filter2D to do so.

For example:

  cv::Mat kernel = cv::getGaussianKernel(3, 0.85, CV_32F);
  kernel = kernel.reshape(1, 1);
  cv::filter2D(img, img, CV_8U, kernel);

Please note that cv::getGaussianKernel returns column filter, so you need reshape to make it horizontal.



来源:https://stackoverflow.com/questions/35012080/how-to-apply-a-partial-derivative-gaussian-kernel-to-an-image-with-opencv

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!