TransWikia.com

Increase contrast of merged Planet Labs scenes

Geographic Information Systems Asked by Peter Pfanne on March 7, 2021

I’ve download a few PlanetScope scenes from Celaya, MX.

Taken alone they have a good contrast.

Then I’ve merged them with gdalbuildvrt, which lowered the contrast: Link

I’ve thought, that I could revert this again by stretching the contrast after this guide. gdalinfo -mm test.vrt gave me:

Band 1 Block=128x128 Type=UInt16, ColorInterp=Red
Computed Min/Max=664.000,48804.000 
Band 2 Block=128x128 Type=UInt16, ColorInterp=Green
Computed Min/Max=3688.000,30697.000 
Band 3 Block=128x128 Type=UInt16, ColorInterp=Blue
Computed Min/Max=19.000,38786.000 
Band 4 Block=128x128 Type=UInt16, ColorInterp=Undefined
Computed Min/Max=2521.000,39791.000

So I’ve stretched the contrast with GDAL

gdal_translate test.vrt out.tif -scale 664 48804 0 65535 -exponent 0.5 -co COMPRESS=DEFLATE -co PHOTOMETRIC=RGB

but the result has even less contrast: Link (all export from QGIS).

What went wrong?

One Answer

I opened file 20180517_164546_0f43_3B_AnalyticMS.tif from the set and opened it with QGIS. With my setting QGIS applies a strech that is based on histograms of each band.

enter image description here

It is possible to do similar stretch with gdal_translate by taking the same values that QGIS uses and telling gdal_translate to use them bandwise with -scale_1, -scale_2, and -scale_3 parameters. Separate scaling of bands is also possible through the GDAL virtual format by using look up tables. LUT makes is also possible to do non-linear stretch. Find LUT from the documentation http://www.gdal.org/gdal_vrttut.html. For the statistically selected min/max values you must still use some other tools.

By looking at the histogram of the image it is easy to see the big difference between the maximum values and 98% percentiles (about 19500 vs 10500).

enter image description here

Edit It should be possible to do automatic, histogram based stretch with Python. There is an example of this in https://pcjericks.github.io/py-gdalogr-cookbook/raster_layers.html "Performs a histogram stretch on a gdalnumeric array image."

Answered by user30184 on March 7, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP