cs498: tip about displaying fft images

39 views
Skip to first unread message

Hoiem, Derek W

unread,
Sep 12, 2012, 11:04:46 PM9/12/12
to cs498-...@googlegroups.com

Part of your first project involves displaying FFT magnitude images.  When doing so, you should use imagesc, which by default scales the colormap to spread across from the min to max value.  Instead, though, you should specify a constant range to display, so that the different FFT plots are comparable.  Details below.

 

To plot the log fft magnitude, use something like:

figure(1), imagesc(log(abs(fftshift(fft2(im)))), [minval maxval]); axis image, colormap jet;

 

Here's why:

  (1) fftshift changes the coordinates so that zero frequency is at the center, like we're used to seeing

  (2) abs computes the magnitude.  The raw output of fft2 contains both phase and magnitude.  Phase is in the angle of the real and imaginary numbers (e.g., call angle(fftim) or atan2(imag(fftim), real(fftim)) to get the phase).   The magnitude is the sqrt of sum of squares of the real and imaginary component.

  (3) log converts to log scale.  The reason for this is that there is so much power in the low frequencies than the high frequencies, that you'll not be able to see anything if you don't look in log scale.  Try it.  You'll basically see a red dot in the middle if you look in linear scale. 

 (4) imagesc plots the image with a specified colormap and rescales the values to the displayable range.  For your homework, you should use the same range for all subplots.  You can specify the range as a second argument ([minval maxval]), e.g., [0 5]. 

 

Derek

Reply all
Reply to author
Forward
0 new messages