Does anyone know how to open a large imagery file using python?
I tried to open an imagery file (about 2 GB) through windows command prompt using ipython, but it crashes every time after I change image values into an array.
My laptop is window7-64bit with 4GB ram and Intel(R) Core(TM) i7-2860 QM CPU.
The error message is: python.exe has stopped working A problem caused the program to stop working correctly. Windows will close the program and notify you if a solution is available
Here is my code.
import Image
import numpy as num
im=Image.open('myimage.tif')
imarray=num.array(im)
How much RAM do you have? You’ll need quite a bit more than 2GB of RAM to store a 2-gig image. I don’t know how efficient
Imageis at storing images, but a list of bytes uses four bytes of space for each element in the list, so you’ll burn more than 8GB of (virtual) memory… and a lot of patience. Edit: Since you only have 4 (or 3) GB to play with, this is almost certainly your problem.But why are you trying to convert it to a numeric array? Use the methods of the
imobject returned byImage.open, as in the PIL Tutorial.I don’t know what you’re doing with the image, but perhaps you can do it without reading the entire image in memory, or at least without converting the entire object into a
numpyarray. Read it bit by bit if possible to avoid blowing up your machine: Read up on python generators, and see theImage.getdata()method, which returns your image one pixel value at a time.