2

.tiff该代码可以从我的 Ubuntu 11.04 上的图像计算傅立叶变换。在 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
4

1 回答 1

1

我试图运行你的代码,除了我用函数替换了mahotas.imreadscipy.misc.imread因为我没有那个库,我无法重现你的错误。

一些进一步的说明:

  • 您可以尝试使用该scipy.misc.imread功能而不是该mahotas功能吗?我想问题可能在那里
  • 抛出的实际异常是什么?(+其他输出?)
  • 你的图像尺寸是多少?灰度/RGB?打印大图像的所有值确实会占用相当多的内存,因此使用 matplotlibsimshow函数等可视化结果可能会更好。
于 2013-06-23T11:09:17.617 回答