1

I would like to automate the process of getting the correct symbology min/max scale for each of the RGB bands via command line.

My use case is I am converting multi-band GEOTIFFs to JPG using the following command

 gdal_translate -ot Byte -of JPG -b 1 -b 2 -b 3 -scale_1 0 439 -scale_2 0 460 -scale_3 0 454 -a_nodata none test.tiff output2.png -co PHOTOMETRIC=RGB

The scales change frequently, and without the correct min and max, the images appear black.

My solution (which does not scale) is I have been getting the scales by loading my GEOTIFFs into the QGIS3 UI software and then looking at what QGIS3 sets for the symbology mins and maxs for each color band. I would like to automate the process of figuring out the color band min/max scales via command line.

2
  • Have you tried computing the statistics of the raster? This should generate the min and max for each band and store that with the metadata. For example: gdal_edit.py your_raster.tif -stats Commented Dec 15, 2018 at 21:01
  • Using just -scale without ranges should do gdal.org/gdal_translate.html but perhaps you must create an interim 3 band image first without scaling.
    – user30184
    Commented Dec 15, 2018 at 21:30

1 Answer 1

2
gdalinfo -mm -stats test.tiff 

The -stats option read and display the image statistics.
If no statistics are stored in the image file, the -mm option forces the computation for each band.

1
  • 1
    thank you again gabriel. I think adding the Metadata:STATISTICS_MEAN + (STATISTICS_STDDEV*2) - gives pretty similar results to what QGIS calculates Commented Dec 16, 2018 at 15:13

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.