Steva
Steva

Reputation: 231

Filtering image with fft

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

Result with simple zero expanding

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 with padded matrix

This is original picture.

original

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

Upvotes: 0

Views: 2010

Answers (1)

Mark Borgerding
Mark Borgerding

Reputation: 8506

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.

Upvotes: 2

Related Questions