Scaling factor of n-dim fft in numpy

708 views Asked by At

I have an image of a grid of holes. Processing it with numpy.fft.fft2 yields a nice image where I can clearly see periodicity, base vectors etc.

But how can I extract the lattice spacing?

The lattice points in real-space have a spacing of about 96px, so the spacing in k-space would be 2*Pi / 96px = 0.065 1/px.

Naturally, numpy can't return an image array with sub-pixel spacing, so it is somehow scaled - spacing in k-space is about 70px.

But how is the scaling done and what is the exact scaling factor?

1

There are 1 answers

0
SleuthEye On

Units of numpy.fft.fft2's output frequency scale is in cycle/full-length/pixel, under the assumption that the input is periodic with a period corresponding to the full input length.

So, if you have an fft2 output with a size of 6720 x 6720 pixels and with a spike at the 70th pixel, you may expect a periodic component in the spatial domain with a period of:

 1 / (70 pixels * 1 cycle / 6720 pixels / pixel) = 96 pixels/cycle.

Correspondingly, if you have an input image with a size of 6720 x 6720 pixels with elements that are repeating every 96 pixels, you will get a spike in the frequency domain at:

(1 / (96 pixels/cycle))  /  (1 cycle / 6720 pixels / pixels) = 70 pixels.

While this is unit accurate, perhaps a simpler way to look at it is:

spatial-domain-period-in-pixels
    = image-size-in-pixels / frequency-domain-frequency-in-pixels
frequency-domain-frequency-in-pixels =
    = image-size-in-pixels / spatial-domain-period-in-pixels