Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why isn't this inverse Fourier transform giving the correct results?

I want to invert the Fourier transform of an image in MATLAB, but the result is not the original image (as it should be). There is obviously some implementation detail that I don't know about that's causing the issue. Here's the code:

img = imread('img.jpg');
fft = fft2(img);
inv = ifft2(fft);
imshow(inv);
like image 890
Christopher Neylan Avatar asked Sep 16 '10 17:09

Christopher Neylan


People also ask

How do you find the inverse of a Fourier transform?

The inverse Fourier transform is defined by(12.4)ℱ−1[g](x)=1(2π)n· ∫ℝnf(ξ)eiξxdξ.

Why we use inverse Fourier transform?

In mathematics, the Fourier inversion theorem says that for many types of functions it is possible to recover a function from its Fourier transform. Intuitively it may be viewed as the statement that if we know all frequency and phase information about a wave then we may reconstruct the original wave precisely.

Is the inverse Fourier transform unique?

It is unique. If the function f(t) is piecewise continious and square integrable the fourier coffiecients are unique.

Is the Fourier transform its own inverse?

Idea. In harmonic analysis, the Fourier inversion theorem states that the Fourier transform is an isomorphism on the Schwartz space of functions with rapidly decreasing partial derivatives. Moreover, it is its own inverse up to a prefactor and reflection at the origin.


1 Answers

Since fft2 and ifft2 both perform calculations in either double or single precision, your image data (which is likely of type uint8) gets converted to type double first before being processed by fft2. You will therefore have to convert your output image inv back to an unsigned 8-bit integer using the function uint8 to recover the original image:

>> img = imread('peppers.png');  % Load a sample image
>> fft = fft2(img);   % Get the Fourier transform
>> inv = ifft2(fft);  % Get the inverse Fourier transform
>> inv = uint8(inv);  % Convert to uint8
>> imshow(inv);       % Show the image
>> isequal(img, inv)  % Test if inv matches the original image img

ans =

     1                % It does!

NOTE: As an additional tip, I would avoid naming your variables fft and inv since functions with those names already exist in MATLAB.

like image 170
gnovice Avatar answered Oct 08 '22 00:10

gnovice