1

I am implementing a code for image enhancement and to apply Fourier and inverse Fourier transform I am using the code below but in result it gives black image.

F = fft2(image); F = fftshift(F); % Center FFT
F = abs(F); % Get the magnitude
F = log(F+1); % Use log, for perceptual scaling, and +1 since log(0) is undefined
F = mat2gray(F); % Use mat2gray to scale the image between 0 and 1
Y = ifft2(F);
subplot(1,1,1);
imshow(Y,[]); % Display the result
Martin Thompson
  • 16,395
  • 1
  • 38
  • 56
FatimaAsif
  • 131
  • 1
  • 14
  • Many fft/ifft implementations will end up with the result being scaled by NxM, leaving it up to you to scale it back to "normal"... I don't recall if Matlab is one of those or not... Also, since you're not doing the ifft of the fft (you've processed the fft in several ways), the result probably won't be what you want... – twalberg Apr 24 '14 at 16:23
  • Making the exact same mistake as [this question](http://stackoverflow.com/questions/19744543/why-isnt-the-inverse-fourier-transform-giving-the-correct-results#comment29339182_19744543). Consider the comments there. – chappjc Apr 24 '14 at 16:56

1 Answers1

2

You try to image the inverse FFT of a matrix which is pure real (and positive), abs(F). The inverse FT of that is a complex one, and since you lose the phase of the original FT, you will get strange result (almost black image, with eventually the first pixel white...).

Second error, you shift the fft to make some computations, but you don't inverse the shift before

For what you want, you have to keep the phase of the FFT:

F = fft2(image); F = fftshift(F); % Center FFT
Fp = angle(F); % Get the phase
F = abs(F); % Get the magnitude
F = log(F+1); % Use log, for perceptual scaling, and +1 since log(0) is undefined
F = mat2gray(F); % Use mat2gray to scale the image between 0 and 1
Y = real(ifft2(ifftshift(F.*exp(1i*Fp))));
subplot(1,1,1);
imshow(Y,[]); % Display the result

Note: you need to take the real part of the inverse FFT since Matlab creates automatically a complex array as output of a FT (direct or inverse), even if it is a real output. You can check this if you see the value of max(abs(imag(Y(:)))), 6e-11 on my computer.

Bentoy13
  • 4,886
  • 1
  • 20
  • 33