Login  Register

Re: FFT of sinusoidal grating

Posted by Michael Schmid on Oct 02, 2008; 2:57pm
URL: http://imagej.273.s1.nabble.com/Competition-ImageJ-Video-Tutorials-tp3694884p3694886.html

Hi Gabriele,

a few more remarks:

for 512x512 your ImageJ result looks resonable, but you have
to note that the 8-bit image displayed as FFT is log-scaled
over many orders or magnitude. All kinds of numerical noise
will be seen in this image.
If you want the power spectrum, use Process>FFT>FFT options.
It will show the two peaks for the sine wave that one should
expect; the numerical noise will be many orders of magnitude
lower.

The IDL result for 512x512 looks like pure noise to me.
I have never used IDL, so I can't comment on your IDL script.

For the images that are not 2^n, ImageJ will extend the canvas
to 2^n size, in this case to 1024x1024. This results in sharp
edges that cause the light gray steaks in your FFT.
If you want to avoid this, scale the image to 2^n before.
Note this works for periodic boundary conditions only;
otherwise you need to multiply your image by some window
function that tapers off smoothly towards the edge (see
http://en.wikipedia.org/wiki/Window_function).
---

Here is a macro for testing that the power spectrum of ImageJ
is correct for a sum of two sine functions:

newImage("test", "32-bit Black", 256, 256, 1);
pi = 3.1415926536;
f1 = 2*2*pi/256;
f2 = 4*2*pi/256;

for (x=0; x<255; x++) {
   v = sin(f1*x)+0.5*cos(f2*x);
   setPixel(x, 0, v);
}
makeRectangle(0, 0, 256, 1);
run("Copy");
for (y=1; y<256; y++) {
   makeRectangle(0, y, 256, 1);
  run("Paste");
}
run("Select None");

run("FFT Options...", "fft raw do");

_____

Michael
________________________________________________________________

On 2 Oct 2008, at 11:45, Gabriele Umbriaco wrote:

> Good day to all.
> If I compute the FFT with ImageJ the result is not the same of IDL.
> I do not understand because, it is wrong ?
> You can help me?
> Thanks you.
> Gabriele
>
> ORIGINAL IMAGE 512x512 http://www.zshare.net/image/19808361cf9f18a5/
> IDL FFT 512x512 http://www.zshare.net/image/198083993bc66e61/
> IMAGEJ FFT 512x512 http://www.zshare.net/image/1980841949a36387/
>
> ORIGINAL IMAGE 800x800 http://www.zshare.net/image/1980603911fc4e4d/
> IDL FFT 800x800 http://www.zshare.net/image/198059600f47c99d/
> IMAGEJ FFT 800x800  http://www.zshare.net/image/198060136c636fcb/
>
>
>>
>> IDL code:
>>
>> ; IDL Version 5.2 (Win32 x86)
>> ; Journal File for rockford@C3B0E6
>> ; Working directory: D:\RSI\IDL52
>> ; Date: Sat Jan 17 18:09:01 2004
>> cd, 'C:\immagini'
>> read_jpeg,'sin_grid_30.jpg',ima
>> image=fltarr(512,512)
>> image(*,*)=ima(1:512,1:512)
>> dimx=512
>> dimy=512
>> window, 1, xs=dimx, ys=dimy, title='original'
>> tvscl,image
>>
>> ;Power Spectrum F(u)*F^(u)
>> window, 2, xs=dimx, ys=dimy, title='Filtered Power Spectrum'
>> pspect= shift((fft(image, -1)*fft(conj(image),1)),dimx/2,dimy/2)
>> tvscl, pspect
>>
>> write_jpeg, 'FFT_IDL.jpg', pspect, Quality=100
>> write_jpeg, 'sin_grid.jpg', image, Quality=100
>>
>> end
> =================================================
> Gabriele Umbriaco