1

I have used this code line to convert my .TIF image to PNG :

C:\Program Files\QGIS 3.26.0>gdal_translate -ot UInt16 -b 1 -b 2 -b 3 -r cubic -of PNG "C:\Users\Cemre\Downloads\0309_0_aug_1.tif" "C:\Users\Cemre\Downloads\0309_0_aug_1.png"

This worked fine but it just gave me a grayscale image though it shows that it is 3 bands. How can I have the rgb version?

1 Answer 1

2

What color interpretation gdalinfo shows for the selected bands 1, 2, and 3? Are they "undefined", or some color like here

Band 2 Block=12000x1 Type=UInt16, ColorInterp=Green

Gdal_translate copies the color interpretation from the source image but it can be overridden with the -colorinterp option https://gdal.org/programs/gdal_translate.html#cmdoption-gdal_translate-colorinterp. In your case the command would be

gdal_translate -ot UInt16 -b 1 -b 2 -b 3 -r cubic -of PNG -colorinterpr red,green,blue "C:\Users\Cemre\Downloads\0309_0_aug_1.tif" "C:\Users\Cemre\Downloads\0309_0_aug_1.png"

Notice that png format does not support color interpretation and therefore this info is stored into .aux.xml sidecar file

... 
<PAMRasterBand band="2">
    <ColorInterp>Green</ColorInterp>
...

If a viewer is aware of the meaning of aux.xml files it can apply the correct color interpretation. One example of such viewers is QGIS.

1
  • I guess windows image viewer does not have this support that QGIS has, so it can't apply the correct color interpretation. I can see the colors in QGIS but not in a regular picture viewer. Thanks.
    – Stud17
    Commented Nov 11, 2023 at 19: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.