【问题标题】:Memory error using scipy.fftpack, how to avoid it?使用 scipy.fftpack 出现内存错误,如何避免?
【发布时间】:2013-06-20 05:42:17
【问题描述】:

我需要在 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

任何帮助将不胜感激!谢谢

【问题讨论】:

  • 你的图片有多大,你有多少内存?

标签: python memory numpy scipy fft


【解决方案1】:

我找到了this discussion,他们在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 行,在 _raw_fft r = work_function(a, wsave) MemoryError
猜你喜欢
  • 2020-07-13
  • 2015-04-18
  • 2023-03-18
  • 2020-06-22
  • 1970-01-01
  • 1970-01-01
  • 2016-11-14
  • 1970-01-01
  • 2017-07-28
相关资源
最近更新 更多