A quick way to implement two-dimensional convolution in C

I am trying to implement a vision algorithm that includes a preliminary stage with a 9x9 Laplace-Gaussian filter. Can you point to a document that briefly explains the quick implementation of the filter? I think I should use FFT for the most efficient filtering.

+5
source share
3 answers

Are you sure you want to use FFT? It will be a conversion of whole arrays, which will be expensive. If you have already decided to use the 9x9 convolution filter, you do not need FFT.

Typically, the cheapest way to perform convolution in C is to create a loop that moves the pointer to the array, summing the collapsed values ​​at each point and writing the data to a new array. Then this loop can be parallelized using your favorite method (compiler vectorization, MPI library, OpenMP, etc.).

Regarding the borders:

  • If you accept values ​​equal to 0 outside the borders, add a 4-element border 0 to your 2nd array of points. This avoids the need for `if` statements to handle borders that are expensive.
  • (.. ), 4- , (abcdefg → fgabcdefgab 2- ). ** : , , FFT **. , , .

4 , 9x9 4 . , n 2n + 1 x 2n + 1.

, , / , , , , . GPU, , , ( ).

+10

http://hebb.mit.edu/courses/9.29/2002/readings/c13-1.pdf

fftw, FFT, ( , , ) http://www.fftw.org/

, , FFT ​​( 9x9). , .

9x9 ( ). !

+2

In fact, you do not need to use an FFT size large enough to store the entire image. You can make many smaller overlapping 2d ffts. You can find "quick convolution" "hide overlap" "overlap add".

However, for a 9x9 kernel. You probably won't see the big benefits.

+1
source

All Articles