The use GDAL TIFFFILE remote sensing image software is converted into readable image

 1. Problem Description:

In some cases, the use of python tifffile library imwrite remote sensing images can not be opened with ENVI software, lack of header information.

2. Solution

TIFFFILE GDAL library using remote sensing image software is converted into readable image

# read TIF image using TIFFFILE and write again using GDAL
def update_msi(input_file_name, output_file_name):
    # 输入:图像路径和保存路径
    # 输出:无,直接保存到硬盘

    img = tifffile.imread(input_file_name)
    rows, cols, bands = img.shape
    driver = gdal.GetDriverByName("GTiff")
    output_data = driver.Create(output_file_name, rows, cols, bands, gdal.GDT_UInt16)
    for band in range(0, bands):
        output_band = output_data.GetRasterBand(band + 1)
        output_band.WriteArray(img[:, :, band])
    output_data.FlushCache()
    output_data = None

update_msi('E:/2019DFC_DATA/Train-Track1-MSI/JAX_031_005_MSI.tif', 'a.tif')

 

Published 38 original articles · 98 won praise · views 360 000 +

Guess you like

Origin blog.csdn.net/xijuezhu8128/article/details/87365964