I'm loading a tiff file from http://oceancolor.gsfc.nasa.gov/DOCS/DistFromCoast/
from PIL import Image
im = Image.open('GMT_intermediate_coast_distance_01d.tif')
The data is large (im.size=(36000, 18000)
1.3GB) and conventional conversion doesn't work; i.e, imarray.shape
returns ()
import numpy as np
imarray=np.zeros(im.size)
imarray=np.array(im)
How can I convert this tiff file to a numpy.array
?
Just install our software TIFF Viewer for Google Chrome™ To begin viewing your TIFF files, simply do the following Install the software TIFF Viewer for Google Chrome™ Click on the software icon Find the TIFF file you wish to open Its that simple, begin viewing your TIFF files online today!
So, OpenCV can always read JPEGs, PNGs, and TIFFs.
May you dont have too much Ram for this image.You'll need at least some more than 1.3GB free memory.
I don't know what you're doing with the image and you read the entire into your memory but i recommend you to read it bit by bit if its possible to avoid blowing up your computer.
You can use Image.getdata()
which returns one pixel per time.
Also read some more for Image.open
on this link :
http://www.pythonware.com/library/pil/handbook/
So far I have tested many alternatives but only gdal worked always even with huge 16bit images.
You can open an image with something like this:
from osgeo import gdal
import numpy as np
ds = gdal.Open("name.tif")
channel = np.array(ds.GetRasterBand(1).ReadAsArray())
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With