MATLAB Answers

0

Why do I receive unexpected results when using FFT2/IFFT2 with a sequence of image arithmetic functions?

I have an image on which I perform some operations in the frequency domain. I do this by using FFT2 to transform the image, and use image processing functions such as IMADD, IMSUBTRACT, etc. to change the transformed image. I then use IFFT2 to change the image back from the frequency domain. However, the image does not look like I would expect, and does not seem to have any of the features of the original image.

1 Answer

Answer by MathWorks Support Team on 10 Nov 2011
 Accepted Answer

The output from FFT2 is always a double. Therefore, the rest of the sequence of operations will be working with doubles. The image arithmetic functions maintain the types of the input. Therefore, they will treat the data as doubles, even though you may have intended for them to be treated like the original image. When you use the image arithmetic functions on a double, it is also possible to produce negative results, because the output will be a double array. Finally, the output from IFFT2 is also always a double and could contain negative values. Therefore, the result of the sequence of operations will be an array of double, instead of the original type.
To work around this issue, you should use IM2DOUBLE to convert the image data to a double, perform the operations, and then convert back to the original data type.
Example:
I = imread('moon.tif');
% convert to double
ID = im2double(I);
% transform to frequency domain
FID = fft2(ID);
% insert image arithmetic operations here
% convert back to spatial domain
IFID = ifft2(FID);
% convert back to uint8
I8 = im2uint8(IFID);

  0 Comments

Sign in to comment.