Reputation: 141
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
Upvotes: 1
Views: 2450
Reputation: 4966
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.
Upvotes: 2