2

I'm taking the fft2 of an image which gives me a complex matrix, but when I transform it back with ifft2 the result is also a complex matrix and it is not the original image. What can be happening here?

image=('file.png');
F_image=fft2(moon);
IF_image=ifft2(F_image);
Pythonice
  • 313
  • 2
  • 6
  • 8
  • 2
    `ifft2` will return complex data even if original data in `fft2` was real due to round-off errors. use `ifft2(F_image,'symmetric')` see documentation in matlab carefully – Guddu Sep 13 '14 at 17:02
  • Ok, that forces the output to be real but I don't get the original image. – Pythonice Sep 13 '14 at 17:14
  • 1
    Can't you just remove the imaginary part of `IF_image`? It will be very small, and you know it's caused only by round-off errors – Luis Mendo Sep 13 '14 at 17:25
  • The problem was actually in my input file. Thanks. – Pythonice Sep 15 '14 at 01:51
  • It's part of the small floating point imprecision when dealing with the FFT. If you know for a fact that your data is real, simply use `real` to obtain the real parts of your image. I also tell you to do that in my post to your previous question shown here: http://stackoverflow.com/questions/25827916/matlab-shifting-an-image-using-fft/25830410#25830410 – rayryeng Sep 15 '14 at 04:32
  • 1
    Your answer is here: http://stackoverflow.com/questions/3729235/why-isnt-this-inverse-fourier-transform-giving-the-correct-results – Failed Scientist Feb 05 '16 at 14:19

1 Answers1

0

Due to approximation, output of IFFT has imaginary parts, but their magnitude will be too low. You can just ignore them, you will get almost same image.

img = imread("c.jpg");
img_gray = rgb2gray(img);
imgfft = fft2(double(img_gray));
opimg = uint8(real(ifft2(imgfft)));
Nawin K Sharma
  • 704
  • 2
  • 6
  • 14