Python 使用scipy.fftpack时出现内存错误,如何避免?

Python 使用scipy.fftpack时出现内存错误,如何避免?,python,memory,numpy,scipy,fft,Python,Memory,Numpy,Scipy,Fft,我需要用Python从.tiff医学图像计算傅里叶系数。该代码产生内存错误: for filename in glob.iglob ('*.tif'): imgfourier = scipy.misc.imread (filename, flatten = True) image = numpy.array([imgfourier])#make an array # Take the fourier transform of the image

我需要用Python从.tiff医学图像计算傅里叶系数。该代码产生内存错误:

for filename in glob.iglob ('*.tif'):
        imgfourier = scipy.misc.imread (filename, flatten = True)
        image = numpy.array([imgfourier])#make an array 
         # Take the fourier transform of the image.
        F1 = fftpack.fft2(image)
         # 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
        print psd2D
任何帮助都将不胜感激!谢谢

我在
scipy.fftpack
中找到了他们发现内存泄漏的地方,建议改用
numpy.fft
包。此外,您还可以节省内存,避免使用中间变量:

import numpy as np
import glob
import scipy.misc
for filename in glob.iglob('*.tif'):
    imgfourier = scipy.misc.imread (filename, flatten = True)
    print np.abs(np.fft.fftshift(np.fft.fft2(np.array([imgfourier]))))**2

文件“C:\Python27\lib\site packages\numpy\fft\fftpack.py”,第75行,在\u raw\u fft r=work\u function(a,wsave)内存中。您的图像有多大,内存有多少?