Ask Your Question
1

gpu::convolve and gpu::filter2D vs cv::filter2D, opencv 2.4.9

asked 2014-06-02 13:22:14 -0600

juancamilog gravatar image

updated 2014-06-02 13:55:42 -0600

I'm trying to use the opencv gpu module to filter an image with Gabor kernels. To check if everything is correct, I'm comparing the result of the CUDA accelerated filtering, with the regular CPU filtering. The code I'm using is available here: https://github.com/juancamilog/gpu_convolve_test.git

Since the funtcion cv::gpu::filter2D is limited to kernels of size smaller than 16x16, I'm using cv::gpu::convolve for larger kernels. In that case, I use cv::gpu::copyMakeBorder to produce a filter response that has the same size as the original image.

The problem I'm facing is that the result of the cv::gpu::convolve function is different from the result of cv::filter2D. What is the cause of this difference? How do we obtain a GPU filtering response that is the same as the CPU filtering response?

UPDATE Some example results for the cv::gpu::filter2D case (no difference):

CPU using CPU filter2D

GPU using GPU filter2D

And for the cv::gpu::convolve case:

CPU using CPU filter2D

GPU using GPU filter2D

edit retag flag offensive close merge delete

Comments

I'm starting to think that this happens because the cuda FFT API is expecting a kernel centered at (0,0): http://developer.download.nvidia.com/compute/cuda/2_2/sdk/website/projects/convolutionFFT2D/doc/convolutionFFT2D.pdf. I can change the code to generate a kernel that has the same size as the image, shifted so the center is at pixel coordinate (0,0), perform the convolution with gpu::dft and gpu::mulSpectrums, and crop the result. Then the result is the expected one, although the computation time is much worse Maybe the fix is to modify the gpu::convolve code so that each block is convolved with a kernel centered at (0,0)?

juancamilog gravatar imagejuancamilog ( 2014-06-05 13:04:45 -0600 )edit

Did you ever figure out how to make this work? Seems like a pretty huge issue. If nothing else, it needs better documentation.

Dagmor gravatar imageDagmor ( 2014-11-19 11:39:12 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2014-11-19 11:38:53 -0600

Dagmor gravatar image

Did you ever figure out how to make this work? Seems like a pretty huge issue. If nothing else, it needs better documentation.

edit flag offensive delete link more

Question Tools

Stats

Asked: 2014-06-02 13:22:14 -0600

Seen: 4,402 times

Last updated: Nov 19 '14