读取并显示遥感影像
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
)
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
band
= image
[bandnumber
-1,:,:]
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
)
结果:
更多内容请关注:测绘科学技术
转载请注明原文地址:https://ipadbbs.8miu.com/read-25029.html