本作者将前段时间用到的opencv数据预处理操作方法进行整理总结方便以后复制粘贴。
数据预处理部分看的东西有点杂,基本什么都在学!!!,最近抽时间将学到的方法陆续整理出来供分享
gdal ReadAsArray支持按块读取影像,有两种方式:
(1)针对dataset
dataset = gdal.Open(file, gdal.GA_ReadOnly)
data = dataset.ReadAsArray(xoff=0, yoff=0, xsize=512, ysize=512)
(2)针对band
dataset = gdal.Open(file, gdal.GA_ReadOnly)
band = dataset.GetBand(0)
data = band.ReadAsArray(xoff=0, yoff=0, win_xsize=512, win_ysize=512)
注意:dataset和band模式中参数不同xsize和win_xsize
ReadAsArray定义:
# dataset.ReadAsArray
def ReadAsArray(self, xoff=0, yoff=0, xsize=None, ysize=None, buf_obj=None,
buf_xsize = None, buf_ysize = None, buf_type = None,
resample_alg = GRIORA_NearestNeighbour,
callback = None,
callback_data = None):
""" Reading a chunk of a GDAL band into a numpy array. The optional (buf_xsize,buf_ysize,buf_type) parameters should generally not be specified if buf_obj is specified. The array is returned"""
# band.ReadAsArray
def ReadAsArray(self, xoff=0, yoff=0, win_xsize=None, win_ysize=None,
buf_xsize=None, buf_ysize=None, buf_type=None, buf_obj=None,
resample_alg = GRIORA_NearestNeighbour,
callback = None,
callback_data = None):
""" Reading a chunk of a GDAL band into a numpy array. The optional (buf_xsize,buf_ysize,buf_type) parameters should generally not be specified if buf_obj is specified. The array is returned"""