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)
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.
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
moon = imread('moon.tif');
% Two dimensional FFT of image
fftOfImage = fft2(moon);
% Absolute value returns the magnitude of the input (eliminates imaginary
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:
c1 = fft2(IAMGE);
c2 = abs(c1);
c3 = log(c2);
c4 = imag(c3);
Do you see the method? Check all intermediate steps to find out, where the unexpected happens.