I'm trying to create an RGB GeoTIFF from an array. I've followed the question and response here, but I'm still having issues. When running gdalinfo on the image, the ColorInterp seem to be correct, but the image is grayscale when I open it in QGIS. Am I creating the file correctly, and/or is this an issue with viewing the image in QGIS?
Here is my code, where the array is a 4-band image of size [4, 5000, 10000]. The bands are b, g, r, nir.
rows, cols = array[0].shape
bands = 4
driver = gdal.GetDriverByName("GTiff")
options = ["PHOTOMETRIC=RGB", "ALPHA=NO", "PROFILE=GeoTIFF"]
outdata = driver.Create(filename, cols, rows, bands, gdal.GDT_Float32, options=options)
outdata.SetGeoTransform(image.GetGeoTransform())
outdata.SetProjection(image.GetProjection())
for i in range(bands):
outdata.GetRasterBand(i + 1).WriteArray(array[i, :, :])
outdata.GetRasterBand(i + 1).SetNoDataValue(-999)
outdata.FlushCache()
outdata = None
array = None
What I expect to end up with is on the left, and what I do end up with is on the right: