python读取遥感影像
2020-07-02 本文已影响0人
陨星落云
读取并显示遥感影像
import numpy as np
from osgeo import gdal
from osgeo.gdalconst import GA_ReadOnly
import matplotlib.pyplot as plt
def disp(infile,bandnumber):
gdal.AllRegister()
inDataset = gdal.Open(infile,GA_ReadOnly)
# print(inDataset)
cols = inDataset.RasterXSize
rows = inDataset.RasterYSize
bands = inDataset.RasterCount
image = np.zeros((bands,rows,cols))
for b in range(bands):
band = inDataset.GetRasterBand(b+1)
image[b,:,:] = band.ReadAsArray(0,0,cols,rows)
inDataset = None
# 显示NIR波段
band = image[bandnumber-1,:,:]
# print(type(band))
mn = np.amin(band) #
mx = np.amax(band)
plt.figure(figsize=(20,18))
plt.imshow((band-mn)/(mx-mn),cmap="gray")
plt.show()
if __name__ == "__main__":
infile = "../data/AST_20070501"
bandnumber = 3
disp(infile,bandnumber)
结果:
显示结果.png