0

I have RGBalpha images stored in a row-major array of structures (RGBa, RGBa, etc.) as 32 bits floats in C99. I need to blur them using large, non-separable, 2D kernels, channel by channel (each channel gets the same kernel). So I figured using the convolution theorem and doing it in Fourier space would be more efficient. I'm using FFTW3.

I saw FFTW3 uses the same data structure for 3D: image[width][height][channels]. For disposable code, before, I use to split each channel apart and do a 2D convolution per channel, but I guess doing it in 3D at once would spare some data flip-flopping. So I'm headed toward 3D, although I'm not really comfortable with Fourier formalism in 3D.

However, there is something I don't make sense of, out of the FFTW3 documentation: what does the fftw_plan_dft_r2c_3d function do ? Is it a channel-wise 2D FFT, or does it do a real 3D FFT with inter-channel frequency decomposition ? That's important because the alpha channel is there for SIMD alignment but is not relevant in the process and should not be linked to the solution.

Then I don't understand how to turn my 2D kernel into something usable in 3D (assuming the previous condition is met). Should I duplicate it along the depth axis (so, stack it 3 times), or only once and pad the remaining depth with zeros ?

Aurélien Pierre
  • 604
  • 1
  • 6
  • 20
  • You must not apply a 3D FFT, but a 2D one to each of your channels. You can plan a 2D transform, and apply it three times. Your kernel should be padded to the same 2D shape and transformed with the same plan, then you multiply it with each of your channels. You can keep your 3D array, that’s fine, but the processing is the same as in 2D, applied to 2D planes of your array. – Cris Luengo Jul 09 '21 at 01:41
  • @CrisLuengo but how can I apply 3 2D transforms on an array of structures ? I don't see anything in the FFTW3 API that allows to skip 3 elements every pixel. Otherwise, I will need to resort to splitting the RGB image into 3 plates, with I/O overhead. – Aurélien Pierre Jul 09 '21 at 02:05
  • 1
    You need to use FFTW’s [advanced interface](https://www.fftw.org/fftw3_doc/Advanced-Interface.html), which allows entering strides (the number of samples to skip to go to the next sample along that dimension). – Cris Luengo Jul 09 '21 at 13:25

0 Answers0