0

I have a question about the Convolve function in OpenCV using GPU acceleration. The speed of the convolutions are roughly 3.5 faster using GPU

when running:

convolve(src_32F, kernel, cresult, false, cbuffer);

However the image borders are missing (in cresult)

The result is excellent otherwise though (kernel size is 60x60)

thanks

1 Answers1

1

This is the way convolution works.

It calculates the value of every pixel as a weighted average of the surrounding ones. So, if you take into account 30 pixels each side, for all the pixels that are closer to the image border than 30 pixels, convolution is not defined.

In the CPU implementation of filtering functions, those missing pixels are supplemented with bogus values based on a given strategy (copy, mirror, blank, etc).

What you can do is to manually pad your matrix with the desired values in a bigger matrix, filter the big one, and then crop it back. For that you can use the gpu::copyMakeBorder() func.

Sam
  • 19,708
  • 4
  • 59
  • 82
  • Hi; Is there some method to the fact that values are slightly overshot. manual adding is not an option for me For example when handling a 320-240 image I add 30 to each size, and the result comes 321-241 (I have manually subtracted one from the top and right. What I mean with method is, for example if kerel side is even then fix, if odd not (or something) – jeffrico el exotico Dec 19 '11 at 09:51
  • The kernel size must be odd. because it is applied symmetrically to the left and right: n values to left, n to right + center. So kernel size must be (2n+1). If you send an even kernel (60/60), maybe it just adds one column and one row in the kernel, and do the same for the image too. – Sam Dec 19 '11 at 10:40
  • But, let me give you a friendly advice: before starting to work on things like CUDA optimizations and complex image processing tasks, please read, understand and apply the basics. Because you will not be able to go forward this way. So, google for `wiki convolution` and read it really, really carefully. – Sam Dec 19 '11 at 10:44
  • :) Thanks for the advice. I do agree with what you say, and this would be the way it is done normally. My task is not really understanding the work, rather than combining various OO components and merging it to fit a existing design. But don't sell me short, things are coming along nicely, despite my ignorance :) In any event, Vasile, I thank you a million – jeffrico el exotico Dec 19 '11 at 12:46
  • BTW: I've just checked and the OpenCV convolve manual does explicitly state that the output is the same size as original, or am I perhaps missuning the component – jeffrico el exotico Dec 19 '11 at 12:50
  • Ok, I'm glad it works :) And the OpenCV doc is not always perfect. – Sam Dec 19 '11 at 13:11