Since FFT2 and IFFT2 both only support inputs of type double
and single
, 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.