# PNG and BMP images with imag(image) = 0. Why and how do I get something that makes sense/a nonzero answer?

1 view (last 30 days)
Jack on 14 Oct 2013
Answered: Jan on 15 Oct 2013
Hi there,
I don't know why, but my MATLAB's telling me that the imag(log(abs(fft2(IMAGE)))) is a big ol' zero matrix. It's a pretty colorful image in .PNG. I tried capturing another image in .BMP and some others in .PNG uint8 to no avail.
Any suggestions?
Sincerely, Jack

Image Analyst on 15 Oct 2013
Well, yeah! What kind of variable do you think abs() produces? Answer: a real variable with no imaginary component. So of course when you ask for the imaginary component of that you'll get zero. What are you trying to do anyway? In general the Fourier Transform of an image will be Hermitian. If it's real and even it will be real. See the third link below for some relationships and proofs.

Jonathan LeSage on 15 Oct 2013
You are using the imag function that returns the imaginary part of the function input. The function input in your case will have no imaginary part, and hence, MATLAB returns a matrix of zeros.
I recommend breaking this command into pieces to debug and see where your issue is arising.
% Import a generic image
% Two dimensional FFT of image
fftOfImage = fft2(moon);
% Absolute value returns the magnitude of the input (eliminates imaginary
% values)
absOfFFT = abs(fftOfImage);
% Log of the FFT, taking the log of a positive real number returns a real number
logOfFFT = log(absOfFFT);
If you want to plot the resulting matrix, check out the imagesc function. Hope this helps!

Jan on 15 Oct 2013
Debugging is a good idea in case of troubles. So split the command into parts:
disp(IMAGE);
class(IMAGE);
size(IMAGE);
c1 = fft2(IAMGE);
disp(c1)
class(c1);
size(c1);
c2 = abs(c1);
disp(c2)
class(c2);
size(c2);
c3 = log(c2);
disp(c3)
class(c3);
size(c3);
c4 = imag(c3);
cisp(c4)
class(c4);
size(c4);
Do you see the method? Check all intermediate steps to find out, where the unexpected happens.