python读取遥感影像

读取并显示遥感影像

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
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。