windows平台安装
直接安装会报错,需要通过下载wheel文件安装
找到对应 python 版本的文件,图中的 cp311 表示 python3.11 版本。
在终端执行下面命令即可成功安装:
pip install GDAL-3.8.4-cp311-cp311-win_amd64.whl
读取tif或tiff图像文件
import numpy as np
from matplotlib import pyplot as plt
from osgeo import gdal
img_path = r"E:\00.tiff"
# 读取图像
dataset = gdal.Open(img_path)
img = dataset.ReadAsArray()
img = (img - np.min(img)) / (np.max(img) - np.min(img))
plt.imshow(img, cmap="gray")
plt.axis("off")
plt.show()