How do I take the FFT and then the IFFT of an image?
5 views (last 30 days)
Show older comments
MathWorks Support Team
on 27 Jun 2009
Commented: Walter Roberson
on 13 Jul 2015
If I take the FFT of an image and then take the IFFT of it, I do not get the original image back. All I get is a black image.
Accepted Answer
MathWorks Support Team
on 27 Jun 2009
The FFT function will return a complex double array. If you read in a .JPG or a .TIF file, you will notice that they are UINT8 arrays. So, you will have to take the real part of the IFFT and then convert it back into UINT8. Try the example below:
IM=imread('flowers.tif'); % Read in a image
whos
image(IM); % Display image
FF = fft(IM); % Take FFT
whos
IFF = ifft(FF); % take IFFT
whos
FINAL_IM = uint8(real(IFF)); % Take real part and convert back to UINT8
whos
figure
imshow(FINAL_IM) % Get back original image.
The WHOS calls in the above code will output the stored variable information so you can see where the conversion to UINT8 is taking place.
1 Comment
Walter Roberson
on 13 Jul 2015
When you start with real data, then after the fft then ifft, the only imaginary part that should be present is due to round-off error. Although taking abs() instead of real() would numerically reduce the round-off error, using uint8() round()'s the data and the round-off error will never be large enough to make a difference on the round() step. There results of uint8(real(IFF)) and uint8(abs(IFF)) would be the same in these circumstances, but uint8(real(IFF)) would require less processor work.
More Answers (0)
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!