我需要从.tiff医学图像中计算Python中的傅立叶系数。代码产生内存错误:
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
任何帮助都会非常感激!感谢
答案 0 :(得分:2)
我发现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