I have a GeoTIFF file which displays the following information when running gdalinfo:

Band 1 Block=10012x1 Type=Float32, ColorInterp=Gray
  Description = Layer_1
  Min=1638.991 Max=2577.040
  Minimum=1638.991, Maximum=2577.040, Mean=2063.003, StdDev=185.546
  NoData Value=-3.4028234663852886e+038

Based on this information, I understand that the minimum and maximum grayscale values are 1638.991 and 2577.040 respectively.

What I want to do is convert this GeoTIFF to a 16-bit PNG image which shows ~938 (2577-1638) different shades of gray. I'm attempting to achieve this with the following gdal_translate command:

"c:\Program Files\GDAL\gdal_translate.exe" -outsize 4096 4096 -of PNG -ot UInt16 -scale 1638.991 2577.040 0 65535 "GDAL_IMG_2_GeoTIFF.tif" "GDAL_IMG_2_GeoTIFF.png"

My understanding here is that -ot UInt16 allows me to create a 16-bit image and -scale 1638.991 2577.040 0 65535 re-maps the geoTIFF grayscale range to the full 16-bit range (0 - 65535).

This command does indeed produce what appears to be a 16-bit image however when viewing the image properties in irfanView, the Number of unique colors is showing as 256.

Full bit-depth info:

irfanView output

Is there any step that I have missed here for creating 16-bit PNG's which make use of > 256 shades of gray or perhaps a better method?


I took bugmenot123's advice and trusted the GDAL output rather than IrfanView which seems to have issues accurately showing bit depth. I double checked the PNG images in QGIS which showed the correct 16-bit range.

| improve this answer | |

Perhaps you should update your gdal. Using version 2.4.0 I can generate 16bit PNGs with this command:

$ gdal_translate -of PNG -ot UInt16 -scale 32.53501 767.4913 0 65535 goes16.abi-2019.0902.1510-C01_1km.tif k.png

$ pngcheck k.png
OK: k.png (2574x1591, 16-bit grayscale, non-interlaced, 35.0%).

The original data is Float32.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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