Hi, I'm trying to convert an image to frequency domain and back using kiss FFT. The problem is that when I ONLY apply the forward transform than (just after that) the inverse transform I obtain a brightened image. I'm using complex numbers this way: const int dims[2] = {h,w}; // dimensions of fft ( height, width) const int ndims = 2; // number of dimensions. here 2 (2D) kiss_fftnd_cfg stf = kiss_fftnd_alloc(dims, ndims, 0, 0, 0), // forward 2d fft configure sti = kiss_fftnd_alloc(dims, ndims, 1, 0, 0); // inverse 2d fft configure kiss_fft_cpx *buf = new kiss_fft_cpx[w * h], *out = new kiss_fft_cpx[w * h]; get Luminance from image and put it inside the array buf like follows: for(every pixel at location x) { // for simplicity here I don't center the spectrum buf[x].r = Luminance[x]; buf[x].i = 0.0; } // forward fft kiss_fftnd(stf, buf, out); // inverse fft kiss_fftnd(sti, out, buf); for(every pixel at location x) // I use just the real part Luminance[x] = buf[x].r ( clipped in the range [0,255] ); set luminance back inside the image free allocated data; This is a very simple code but it doesn't work like it's supposed to. I hope someone can help me. Thanks in advance.
Can't transform properly using kiss fft
Started by ●November 22, 2007
Reply by ●November 24, 20072007-11-24
I solved the problem myself, but to think that I had to apply a convolution just to normalize the values... "4N" <xxxx@yyyy.zzz> ha scritto nel messaggio news:47455386$0$36447$4fafbaef@reader5.news.tin.it...> Hi, > I'm trying to convert an image to frequency domain and back using kiss > FFT. > The problem is that when I ONLY apply the forward transform than (just > after that) the inverse transform I obtain a brightened image. > I'm using complex numbers this way: > > const int dims[2] = {h,w}; // dimensions of fft ( height, width) > const int ndims = 2; // number of dimensions. here 2 (2D) > kiss_fftnd_cfg stf = kiss_fftnd_alloc(dims, ndims, 0, 0, 0), // forward > 2d fft configure > sti = kiss_fftnd_alloc(dims, ndims, 1, 0, 0); // inverse 2d fft configure > kiss_fft_cpx *buf = new kiss_fft_cpx[w * h], > *out = new kiss_fft_cpx[w * h]; > > get Luminance from image and put it inside the array buf like follows: > > for(every pixel at location x) > { > // for simplicity here I don't center the spectrum > buf[x].r = Luminance[x]; > buf[x].i = 0.0; > } > > > // forward fft > kiss_fftnd(stf, buf, out); > // inverse fft > kiss_fftnd(sti, out, buf); > > for(every pixel at location x) > // I use just the real part > Luminance[x] = buf[x].r ( clipped in the range [0,255] ); > > set luminance back inside the image > > free allocated data; > > This is a very simple code but it doesn't work like it's supposed to. > I hope someone can help me. > > Thanks in advance. > >
Reply by ●November 27, 20072007-11-27
4N wrote:> I solved the problem myself, but to think that I had to apply a convolution > just to normalize the values...I'm not sure why you would need "convolution just to normalize the values". From what I can tell, your problem was simply scaling. Many FFT libraries have a non-unity gain when doing ifft( fft(x) ). Did you read the README file? I know some people are morally opposed to reading documentation, but it is barely 100 lines long. It has a whopping two FAQs. The second one would've solved your problem: " Q: Why don't I get the output I expect? A: The two most common causes of this are 1) scaling : is there a constant multiplier between what you got and what you want? 2) mixed build environment -- all code must be compiled with same preprocessor definitions for FIXED_POINT and kiss_fft_scalar However ... with that said, one of these days I will probably make kiss_fft do round-trip scaling. I get the scaling question often enough to make me realize that the library is not as fool-proof as it could be. -- Mark