How to make FFT in Numpy

This seems like a very simple question, but I could not find any documentation for this.

I have an image in Numpy and I want to imshow FFT.

In matlab, I can just do

 F = fft(myimg) imshow(F) 

I can't do the same in Numpy, because F is complex-valued. Trying to make imshow(real(F)) gives me the whole black image - I suppose because in [0,1] instead of 0..255. Multiplying by 255 also does not fix the problem.

Any ideas on how to get my plot?

Update:

Well, Nathan pointed out how I improperly simplified this problem. Let me back off a bit. I have a video matrix of sizes (200, 30, 30, 3). 200 frames, 30x30 pixels, 3 color channels. For each color channel of each pixel, I want to calculate the fft of this pixel over time in a series. This should give me a new matrix, which is (200,30,30,3). For each pixel, for each color channel, a 200-dimensional temporal Fourier transform of each pixel. Then I must be able to watch, for example. an image created by the values โ€‹โ€‹of the first Fourier transform coefficient in each pixel.

Note that matlab fft works with the first non-singular dimension, so F = fft(video) does what I need.

+4
source share
1 answer

Here is an example for a 2D image using scipy:

 from scipy import fftpack import numpy as np import pylab as py # Take the fourier transform of the image. F1 = fftpack.fft2(myimg) # Now shift so that low spatial frequencies are in the center. F2 = fftpack.fftshift( F1 ) # the 2D power spectrum is: psd2D = np.abs( F2 )**2 # plot the power spectrum py.figure(1) py.clf() py.imshow( psf2D ) py.show() 

For 1D tracks you can see an example here ...

+9
source

All Articles