6

I have a raster which has 4 bands, however band 4 is not being interpreted as an alpha channel. When I run gdalinfo I get the follow information about the bands:

Band 1 Block=360000x1 Type=Byte, ColorInterp=Gray
Band 2 Block=360000x1 Type=Byte, ColorInterp=Undefined
Band 3 Block=360000x1 Type=Byte, ColorInterp=Undefined
Band 4 Block=360000x1 Type=Byte, ColorInterp=Undefined

I would like it to look like this:

Band 1 Block=360000x1 Type=Byte, ColorInterp=Red
  Mask Flags: PER_DATASET ALPHA
Band 2 Block=360000x1 Type=Byte, ColorInterp=Green
  Mask Flags: PER_DATASET ALPHA
Band 3 Block=360000x1 Type=Byte, ColorInterp=Blue
 Mask Flags: PER_DATASET ALPHA
Band 4 Block=360000x1 Type=Byte, ColorInterp=Alpha

I am able to do this in QGIS by setting the band 4 to transparent and then rendering out the raster.

Is there a way of changing the "ColorInterp" in GDAL as I want to automate the process?

0

1 Answer 1

8

Should be doable with gdal_edit.py http://www.gdal.org/gdal_edit.html

-colorinterp_X red|green|blue|alpha|undefined:

(GDAL >= 2.3) Change the color interpretation of band X (where X is a valid band number, starting at 1)

The whole command would look like

gdal_edit -colorinterp_1 red -colorinterp_2 green -colorinterp_3 blue -colorinterp_4 alpha image.tif
1
  • 1
    Great, I found that GDAL's translate tool in QGIS also supports this command: colorinterp_X <red|green|blue|alpha|gray|undefined>
    – Buff Fox
    Mar 10, 2023 at 0:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.