Python归一化tif文件
#!/usr/bin/env python
# -*- coding:utf-8 -*-
# @Time : 2019/6/25 10:39
# @Author : wangyu
# @File : Duo.py
# @Software: PyCharm
import os
import numpy as np
from osgeo import gdal
import glob
import datetime
# 读图像文件
def read_img(filename):
dataset = gdal.Open(filename) # 打开文件
im_width = dataset.RasterXSize # 栅格矩阵的列数
im_height = dataset.RasterYSize # 栅格矩阵的行数
im_geotrans = dataset.GetGeoTransform() # 仿射矩阵
im_proj = dataset.GetProjection() # 地图投影信息
im_data = dataset.ReadAsArray(0, 0, im_width, im_height).astype(np.float) # 将数据写成数组,对应栅格矩阵
del dataset # 关闭对象,文件dataset
return im_proj, im_geotrans, im_data, im_height, im_width
def write_img(filename, im_proj, im_geotrans, im_data):
# gdal数据类型包括
# gdal.GDT_Byte,
# gdal .GDT_UInt16, gdal.GDT_Int16, gdal.GDT_UInt32, gdal.GDT_Int32,
# gdal.GDT_Float32, gdal.GDT_Float64