I have some Python code to write 3 channels to file. Here, channels is an array of 3 numpy 2D-arrays (RGB), outfile is the filename, and rows and cols are the image dimensions.
def save_tiff(channels, outfile, rows, cols): outdriver = gdal.GetDriverByName("GTiff") outdata = outdriver.Create(str(outfile)+".tif", rows, cols, len(channels), gdal.GDT_Byte) # write the arrays to the file i = 1 for c in channels: outdata.GetRasterBand(i).WriteArray(c) outdata.GetRasterBand(i).FlushCache() i += 1
However, this results in 24-bit output images (probably because of 3xGDT_Byte channel). How do I get a single 8-bit image from 3 channels (R,G,B) in Python using gdal?