[GIS] NIR, R, G, B multiband (4 Band) GeoTIFF gdal_translate colorinterp issues

gdalgeotiff-tiffmulti-bandrasteriorio

I originally create a 5 band image (NIR, R, G, B, NDVI) from Sentinel 2 Sat imagery that has valid data in the bands to work with. I'm stacking them together with rio stack command.

rio info 5band.tif

{"count": 5, "crs": "EPSG:32614", "colorinterp": ["gray", "undefined", 
"undefined", "undefined", "undefined"], "interleave": "pixel", "dtype": 
"uint8", "driver": "GTiff", etc...}

NIR, G, B in QGIS from 5 band:
enter image description here

However, if I try to use either rio cli or for instance the following gdal_translate command to create a new GeoTIFF with only the first 4 bands (NIR, R, G, B), the colorinterp changes for the bands and the image output appears to be substantially lighter because its setting the 4th band as alpha on the colorinterp which gets loaded as transparency.

gdal_translate -b 1 -b 2 -b 3 -b 4 5band.tif 4band.tif

{"count": 4, "crs": "EPSG:32614", "colorinterp": ["gray", "green", 
"blue", "alpha"], "interleave": "pixel", "dtype": "uint8", "driver": 
"GTiff", etc...]}

NIR, G, B in QGIS from 4 band:
enter image description here

Any ideas why this is happening and what I can do to prevent it from registering the 4th band as alpha?

Best Answer

Using the creation option -co "ALPHA=NO" param in the gdal_translate command prevented the 4th band being set as alpha (its set as undefined now) which solved the issue.

This solution was found here: How can I use gdal_retile on RGBI (4 band) GeoTIFFs while preserving band information?

Related Question