如何在python中读取大的tif文件? [英] How to read a big tif file in python?

查看:2005
本文介绍了如何在python中读取大的tif文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从 http://oceancolor.gsfc.nasa.gov加载tiff文件/DOCS/DistFromCoast/

from PIL import Image
im = Image.open('GMT_intermediate_coast_distance_01d.tif')

数据很大(im.size=(36000, 18000) 1.3GB),常规转换无效;即imarray.shape返回()

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)

如何将该tiff文件转换为numpy.array?

How can I convert this tiff file to a numpy.array?

推荐答案

到目前为止,我已经测试了许多替代方法,但只有 gdal 即使使用巨大的16位图像也始终可以工作.

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())

这篇关于如何在python中读取大的tif文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆