问题
I am trying to apply filter to image using 2D FFT. I have filter matrix (convolution kernel etc), but if I want to use fft I need to expand filter and picture matrix to power of 2 square matrix.
First I expand it with zeros (so matrix of picture and filter would be in top left corner of big power of 2 matrix) and I got this result
Then I tried what I did with picture matrix when I was applying convolution without fft, padded picture matrix with filter dimension/2 from each side, and than that padded matrix with simple expand filter matrix to power of 2 matrix to convolve with fft and i got this
This is original picture.
About algorithm: I am applying 2d fft on both expanded matrixes and than dotwise multiply matrixes after what Im doing simple inverse fft. Also picture matrix are number from 0 to 16M (first 8 bits are red, second 8 bits are green and third 8 bits are blue)
I think that problem is in way how I am expanding picture and filter matrix to square power of 2 matrix but im not sure. I tested fft functions (fft and inverse fft, i got same picture (without dotwise multiplication))
Also filter is
0 .2 0
.2 .2 .2
0 .2 0
回答1:
You don't need to transform the image all at once. Use FFTs on subblocks. Overlap the transformed subimages by the kernel size and either discard the wraparound transient (overlap-save) or add the input-on and input-off transients (overlap-add).
Understand fast convolution in one dimension before you try to do it in two.
来源:https://stackoverflow.com/questions/14328502/filtering-image-with-fft