Windows下使用NumPy数组对图像进行快速傅立叶变换时的内存错误

2024-06-16 14:29:24 发布

您现在位置:Python中文网/ 问答频道 /正文

代码可以从我的ubuntu11.04上的.tiff图像计算傅立叶变换。在WindowsXP上,它会产生内存错误。要改变什么?谢谢您。在

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

错误输出为:

^{pr2}$

Tags: theinimagenonefor错误nptransform
1条回答
网友
1楼 · 发布于 2024-06-16 14:29:24

我试图运行您的代码,但我用^{}函数替换了mahotas.imread,因为我没有该库,无法重现您的错误。在

进一步说明:

  • 你能试着用scipy.misc.imread函数代替mahotas函数吗?我想问题可能就在那里
  • 抛出的实际异常是什么?(+其他输出?)在
  • 你的形象有多大?灰度/RGB?打印大图像的所有值确实会占用相当多的内存,因此使用matplotlibsimshow函数来可视化结果可能会更好。在

相关问题 更多 >