将ETOPO tiff图像读入numpy数组(Python)

f45qwnt8  于 2023-02-08  发布在  Python
关注(0)|答案(1)|浏览(128)

我正在Python https://www.ngdc.noaa.gov/mgg/global/relief/ETOPO2022/data/15s/15s_surface_elev_gtif/中读取其中一个图像
它们是灰度tiff图像。我设法用Pillow(PIL)库阅读了它们:

im = Image.open(filepath)

一切都很好。我得到了尺寸为3600 x 3600的东西,这看起来很合理。
现在我想看看像素值,所以我尝试创建一个numpy数组:

imarray = numpy.array(im)

用不同的参数,但我总是一无所获(大小= 1)。有没有人尝试过读取这些图像并成功访问像素值?问题是否与32位灰度值有关?
我也尝试过其他方法,使用imageio和cv2库,但到目前为止运气不好。我对Python和这些库相对来说是新手,所以可能我在这里走错了方向。有人尝试过这些特定的库并取得了成功吗?

sr4lhrrt

sr4lhrrt1#

这些图像是用 “Adobe Deflate” 压缩的。你可以用exiftool这样来判断:

exiftool YOURIMAGE.TIF
...
...
Compression                     : Adobe Deflate
...

在这种情况下,您需要将libtiff安装到decompress映像中。您可以这样来判断:

python3 -m PIL
--------------------------------------------------------------------
Pillow 9.1.1
Python 3.10.0 (v3.10.0:b494f5935c, Oct  4 2021, 14:59:19) [Clang 12.0.5 (clang-1205.0.22.11)]
--------------------------------------------------------------------
Python modules loaded from /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/PIL
Binary modules loaded from /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/PIL
--------------------------------------------------------------------
--- PIL CORE support ok, compiled for 9.1.1
--- TKINTER support ok, loaded 8.6
--- FREETYPE2 support ok, loaded 2.12.1
--- LITTLECMS2 support ok, loaded 2.14
--- WEBP support ok, loaded 1.2.4
--- WEBP Transparency support ok
--- WEBPMUX support ok
--- WEBP Animation support ok
--- JPEG support ok, compiled for libjpeg-turbo 2.1.3
--- OPENJPEG (JPEG2000) support ok, loaded 2.5.0
--- ZLIB (PNG/ZIP) support ok, loaded 1.2.12
--- LIBTIFF support ok, loaded 4.4.0
--- RAQM (Bidirectional Text) support ok, loaded 0.9.0, fribidi 1.0.12, harfbuzz 5.3.1
*** LIBIMAGEQUANT (Quantization method) support not installed
--- XCB (X protocol) support ok
--------------------------------------------------------------------
BLP
Extensions: .blp
Features: open, save, encode
--------------------------------------------------------------------
...
...
...

所以,我想你需要安装libtiff。你怎么做取决于你的操作系统。

相关问题