【问题标题】:Saving a large color image as `GTiff` with `gdal`使用“gdal”将大型彩色图像保存为“GTiff”
【发布时间】:2017-03-04 02:33:44
【问题描述】:

我正在尝试保存大小为(15000, 80000, 3) 的大图像。这个数组是一个 numpy 数组,我初始化为 im_final = np.zeros((15000,80000,,3))。为了进行保存,我使用gdal,如下所示:

dst_ds = gdal.GetDriverByName('GTiff').Create('val.tif', 80000, 15000, 3, gdal.GDT_Byte)
dst_ds.GetRasterBand(1).WriteArray(im_final[:,:,0])   # write r-band to the    raster
dst_ds.GetRasterBand(2).WriteArray(im_final[:,:,1])   # write g-band to the raster
dst_ds.GetRasterBand(3).WriteArray(im_final[:,:,2])   # write b-band to the raster
dst_ds.FlushCache()                     # write to disk
dst_ds = None

当我保存它时,生成的图像是黑白的。但是,我需要图像是 RGB,有人知道问题是什么吗?此外,im_final 中的值为uint16

【问题讨论】:

    标签: python image numpy gis gdal


    【解决方案1】:

    问题是您试图将uint16 写入uint8 (gdal.GDT_Byte) 图像。如果您确实需要 8 位图像(例如,如果您想在非 GIS 程序中查看此图像),最佳做法是将im_final 缩放到 0-255 之间。这可以是从 0-65535 到 0-255 或每个波段的最小/最大值到 0-255 或任何其他数量的方式的映射。

    如果im_final 中的值很重要,则在driver.Create() 中使用gdal.GDT_UInt16

    【讨论】:

    • 啊,我只能在 GIS 程序中查看uint16 输出吗?我尝试在我的 Mac 上查看输出,但出现此错误:It may be damaged or use a file format that Preview doesn’t recognize.
    • 有很多程序可以处理 16 位图像(Adobe Photoshop、其他图像处理软件、GIS)。例如,如果您想将图像发布到网络上,那么 8 位 RGB(jpeg 或 png)可能是您的最佳选择。
    猜你喜欢
    • 2014-09-28
    • 1970-01-01
    • 2019-07-21
    • 1970-01-01
    • 2019-10-24
    • 2016-11-25
    • 1970-01-01
    • 1970-01-01
    • 2015-05-02
    相关资源
    最近更新 更多