fft2 and ifft2 don't return my original image, even with no transformations

7 views (last 30 days)
I'm trying to perform transformations on an image using fourier transforms. But before I start properly modifying the image, I'm already running into an error simply running:
imagesc(ifft2(fft2(imread('images/obama.jpg'))));
To my mind, running fft2 and its inverse should return the same image, but I get an error that it is outputting a complex values. So I tried:
imagesc(abs(ifft2(fft2(imread('images/obama.jpg')))));
Adding in an abs or an angle to return to real values gives a glitchy mess, just about recognisable as the original image:
What am I missing here? What steps are necessary to fourier my image and back?

Answers (1)

Matt J
Matt J on 13 Mar 2021
Edited: Matt J on 13 Mar 2021
Convert the image to double floats before you start taking FFTs.
Also, be mindful that your image has RGB color channels. Did you intend to take the FFT of each channel separately or did you expect to be working with a single-channel image? If the latter, convert the image using rgb2gray().

Categories

Find more on Fourier Analysis and Filtering in Help Center and File Exchange

Products


Release

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!