批量將多波段圖像提取為各個單波段圖像
運行環境:windows10 pycharm python3.7.7 GDAL-3.2.3-cp37-cp37m-win_amd64.whl包等。
"""
此段代碼將遙感圖像背景值去除處理
"""
import numpy as np
from osgeo import gdal, gdalconst
import os
#將遙感影像歸一化處理 寫成函數
def GetEnvolopePoint(inputpath,output_filepath):
gdal.UseExceptions()
ds = gdal.Open(inputpath)
band01 = ds.GetRasterBand(1)
im_width, im_height = band01.XSize, band01.YSize
print(inputpath,"影像大小為:",im_width, im_height)
dim_z = ds.RasterCount #圖像通道數
if dim_z>5:
dim_z=5 #只提取前5個波段
for i in range(1, dim_z + 1):
band = ds.GetRasterBand(i)
band_array = band.ReadAsArray()
print("Image Shape:", band_array.shape)
文章目錄前言一、Sub-function details1.