我需要用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任何帮助都将不胜感激!谢谢
发布于 2013-06-24 02:02:40
我发现了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]))))**2https://stackoverflow.com/questions/17263241
复制相似问题