我正在尝试保存大小为(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
。
答案 0 :(得分:3)
问题是您正在尝试将int main(){
vector <json> alljSon;
std::ifstream i("test.json");
while (i.good()) {
json j;
i >> j;
alljSon.push_back(j);
}
return 0;
写入uint16
(uint8
)图片。如果您确实需要8位图像(例如,如果要在非GIS程序中查看此图像),最佳做法是将gdal.GDT_Byte
缩放到0-255之间。这可以是从0-65535到0-255或每个波段的最小/最大值到0-255或任何其他方式的映射。
如果im_final
中的值很重要,请在im_final
中使用gdal.GDT_UInt16
。