0

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.

  • 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 – Charlie Parr Dec 15 '18 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 Dec 15 '18 at 21:30
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
    thank you again gabriel. I think adding the Metadata:STATISTICS_MEAN + (STATISTICS_STDDEV*2) - gives pretty similar results to what QGIS calculates – user1709076 Dec 16 '18 at 15:13

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.