2

The code could compute Fourier transform from a .tiff image on my Ubuntu 11.04. On Windows XP it produces memory error. What to change? Thank you.

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

The error output is:

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

1 Answer 1

1

I've tried to run your code, except that I replaced the mahotas.imread with the scipy.misc.imread function, because I don't have that library, and I could not reproduce your error.

Some further remarks:

  • can you try to use the scipy.misc.imread function instead of the mahotas function? I suppose the issue could be there
  • what is the actual exception that is thrown? (+other output?)
  • what are the dimensions of your image? Gray-scale / RGB? Printing all values for a large image could indeed take up quite some memory, so it might be better to visualize the results with e.g. matplotlibs imshow function.
6
  • Thank you, I have tried scipy function for reading the image, but result is the same, see the log error output
    – KvasDub
    Jun 23, 2013 at 11:40
  • What are the dimensions of the image? i.e. try print imgfourier.shape also, you could try to use the flatten=True option in imread: imgfourier = imread(filename, flatten=True) #read the image
    – martyn
    Jun 23, 2013 at 12:02
  • thank you, image is a 90 MB .tiff (merged from 10 of them using IrphanView)
    – KvasDub
    Jun 23, 2013 at 16:04
  • I set flatten = true for scipy.misc.imread function, same memory error occurs, thanks
    – KvasDub
    Jun 23, 2013 at 16:12
  • 90 MB tiff image seems rather large; could be that the imread function is not suited for handling such large images. What do you mean by that it's merged from 10 other images? Are you by any chance trying to read a 3d (medical) image volume? Could you also test your code on another tif image?
    – martyn
    Jun 24, 2013 at 11:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.