3
$\begingroup$

I have a image and I want calculate fft2 of it, after it I want recover image only by magnitude of it. how can I achieve this work?

I=imread('1.bmp');
I = rgb2gray(I);
imafft = fft2(double(I));

 % Gets magnitude and phase.
 mag = abs(imafft);

 % Generates the modified spectrum
 newfft = mag.*exp(0*angle(imafft));
 ima_out = ifft2(newfft);
 imshow(abs(ima_out));

this is return me white page.

$\endgroup$
  • $\begingroup$ I suggest posting 1.bmp so that others can try it. $\endgroup$ – Jim Clay May 15 '13 at 14:39
  • $\begingroup$ You can't do that. ysbl.york.ac.uk/~cowtan/fourier/magic.html $\endgroup$ – endolith May 15 '13 at 15:19
  • 2
    $\begingroup$ The reason the image is all white is because ifft2 returns doubles, and imshow assumes doubles to be normalized to [0,1], which these probably aren't. Changing the last line to imshow(abs(ima_out),[]) will set the range dynamically, but as Jim Clays's answer has already pointed out, this information is all garbage anyways. $\endgroup$ – Sam Maloney May 15 '13 at 19:54
  • $\begingroup$ imagesc is another good one $\endgroup$ – geometrikal May 16 '13 at 5:43
6
$\begingroup$

Check out this classic example from Oppenheim, A. V., & Lim, J. S. (1981). "The importance of phase in signals". a) and b) are the original images, c) is the image created using the phase of a) with the magnitude of b), d) is the image created using the phase of b) and the magnitude of a). Phase carries most of the information in an image.

enter image description here

$\endgroup$
2
$\begingroup$

You cannot recover an image with just the frequency magnitudes. You need the phase information as well to recover it.

$\endgroup$
  • $\begingroup$ I dont want recover whole image ,recover image with magnitude or phase have result but not good result . see this link.nptel.iitm.ac.in/courses/Webcourse-contents/IIT-KANPUR/… $\endgroup$ – Yusef Mohamadi May 15 '13 at 13:42
  • 2
    $\begingroup$ Right, the link says the same thing I did, that recovering with the magnitude only doesn't work. So what are you trying to do? $\endgroup$ – Jim Clay May 15 '13 at 13:48
  • $\begingroup$ I just want to test if I want recover my image by magnitude what image recovered, ( I know recovering by magnitude or phase solely not return perfect image ) .but I want recover only by magnitude. $\endgroup$ – Yusef Mohamadi May 15 '13 at 14:07
  • 1
    $\begingroup$ Try recovering with just the phase and you should get something recognizable. As you have seen and as your own link shows, recovering with just the magnitude produces totally unrecognizable images. $\endgroup$ – Jim Clay May 15 '13 at 14:33
  • $\begingroup$ I konw, I dont want regonizable image,I just want magnitude of images, I try my code but only return white page to me, where is problem? $\endgroup$ – Yusef Mohamadi May 15 '13 at 14:36
1
$\begingroup$

Try using im2double instead of

fft2(double(I));

So, will be like:

ima_double = im2double(I);

imafft = fft2(ima_double);

And when you will show the output image use:

ima_out_u8 = im2uint8(ima_out);

imshow(ima_out_u8);

And a better explanation can be found here.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.