PNG and BMP images with imag(image) = 0. Why and how do I get something that makes sense/a nonzero answer?
4 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
回答(3 个)
Image Analyst
2013-10-15
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.
Helpful links:
0 个评论
Jonathan LeSage
2013-10-15
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
% 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!
0 个评论
Jan
2013-10-15
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.
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!