使用Windows下的NumPy数组对图像进行快速傅里叶变换时的MemoryError

时间:2013-06-23 10:44:43

标签: python windows numpy fft

代码可以从我的Ubuntu 11.04上的.tiff图像计算傅立叶变换。在Windows XP上,它会产生内存错误。有什么改变?谢谢。

def fouriertransform(result):     #function for Fourier transform computation
    for filename in glob.iglob ('*.tif')
        imgfourier = scipy.misc.imread(filename) #read the image
        arrayfourier = numpy.array([imgfourier])#make an array 
        # Take the fourier transform of the image.
        F1 = fftpack.fft2(arrayfourier)
        # 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
        L = psd2D
        np.set_printoptions(threshold=3)
        #np.set_printoptions(precision = 3, threshold = None, edgeitems = None, linewidth = 3, suppress = True, nanstr = None, infstr = None, formatter = None)
        for subarray in L:
            for array in subarray:
                for array in subarray:
                    for elem in array:
                        print '%3.10f\n' % elem

错误输出为:

Traceback (most recent call last):
  File "C:\Documents and Settings\HrenMudak\Мои документы\Моя музыка\fourier.py", line 27, in <module>
    F1 = fftpack.fft2(arrayfourier)
  File "C:\Python27\lib\site-packages\scipy\fftpack\basic.py", line 571, in fft2
    return fftn(x,shape,axes,overwrite_x)
  File "C:\Python27\lib\site-packages\scipy\fftpack\basic.py", line 521, in fftn
    return _raw_fftn_dispatch(x, shape, axes, overwrite_x, 1)
  File "C:\Python27\lib\site-packages\scipy\fftpack\basic.py", line 535, in _raw_fftn_dispatch
    return _raw_fftnd(tmp,shape,axes,direction,overwrite_x,work_function)
  File "C:\Python27\lib\site-packages\scipy\fftpack\basic.py", line 463, in _raw_fftnd
    x, copy_made = _fix_shape(x, s[i], waxes[i])
  File "C:\Python27\lib\site-packages\scipy\fftpack\basic.py", line 134, in _fix_shape
    z = zeros(s,x.dtype.char)
MemoryError

1 个答案:

答案 0 :(得分:1)

我尝试运行您的代码,只是我用scipy.misc.imread函数替换mahotas.imread,因为我没有该库,我无法重现您的错误。

进一步评论:

  • 您可以尝试使用scipy.misc.imread函数而不是mahotas函数吗?我想问题可能就在那里
  • 抛出的实际异常是什么? (+其他输出?)
  • 您图片的尺寸是多少?灰度/ RGB?打印大图像的所有值确实会占用相当多的内存,因此用例如可视化结果可能更好。 matplotlibs imshow函数。