Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to apply a partial derivative Gaussian kernel to an image with 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 ?

like image 344
Baptiste Wicht Avatar asked Feb 07 '23 22:02

Baptiste Wicht


1 Answers

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.

like image 84
akarsakov Avatar answered Apr 06 '23 22:04

akarsakov