I need to do 2D convolution using C++. I am looking for a function like MATLAB's conv2 function, but for C++.

I am not looking for any general tips, such as:

  • Why don't you use fftw for implementation?
  • Why don't you write it yourself for small kernel sizes using for loops?

Because I am 100% sure that many people already have been doing this in a much better way then I will be able to, ever.

Like I said, I am looking for a function like conv2, taking a matrix, a kernel and that let me specify the mode like 'same' http://de.mathworks.com/help/matlab/ref/conv2.html?refresh=true

I have been using Armadillo in the project so far, it only comes with a 1D convolution function. The only library I could come up with providing a 2D convolution is OpenCV. But I would prefer to not add a new giant library only because I am missing one function especially because I am using Qt for displaying graphics.

Any additional suggestions other than OpenCV?


So, it is possible to create C/C++ code from Matlab code, using the Matlab Coder. If you are willing to use Octave instead, then the Octave libraries can also be used as standalone applications, see here (which might be even closer to what you are/where looking for).

| improve this answer | |

After getting in contact with the developer of Armadillo, he added a conv2 function.So now Armadillo can be used.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.