GDAL GeoTIFF – How to Display Bright and Realistic GeoTIFF Using GDAL

colorgdalgdal-mergemerge

I am using GDAL (gdal_merge) to put together some landsat photos using the proper bands. When I open the GeoTIFF that is created using gdal_merge (in Windows), the GeoTIFF is super dark. Now, when I open the same GeoTIFF in ArcMap, it's nice and bright and realistic looking. I was wondering if there was a function in GDAL that would allow me to do what ArcMap is doing.
I have tried using PIL (in python) to enhance the brightness, contrast, and color – and I have had some success, but certainly it's not as nice as what ArcMap is doing.

Does anyone have any ideas? Just in case you are wondering, the gdal_merge command is as follows

gdal_merge.py -separate -ps 16 16 -co PHOTOMETRIC=RGB -o "merged_new.tif" "LC08_L1TP_046029_20180717_20180717_01_RT_b4.tif" "LC08_L1TP_046029_20180717_20180717_01_RT_b3.tif" "LC08_L1TP_046029_20180717_20180717_01_RT_b2.tif"

But I don't think the gdal_merge command is an issue, as I am opening the result of gdal_merge with arcmap and it looks nice.

Best Answer

ArcMap stretches the values of a raster automatically by some clip algorithm (percent clip).

You can use gdal_translate -scale option to "scale"/stretch the values.

-scale [src_min src_max [dst_min dst_max]]:
Rescale the input pixels values from the range src_min to src_max to the range dst_min to dst_max. If omitted the output range is 0 to 255. If omitted the input range is automatically computed from the source data.

So you need to find out the right values by yourself. Use gdalinfo -hist merged_new.tif to find see the values of the file.

Assuming most values (98%) lie between values of 20 and 150, we can do this:

gdal_translate -of GTiff -ot Byte -scale 20 150 0 255 merged_new.tif merged_new_scaled.tif

For your Landsat scene, you posted this information:

Metadata: STATISTICS_MAXIMUM=35050 STATISTICS_MEAN=3832.5215314015 STATISTICS_MINIMUM=0 STATISTICS_STDDEV=4860.9555695374 Band 3 Block=9697x1 Type=UInt16, ColorInterp=Blue

That is a 16 Bit image. If you want an 8bit (=Byte) image to view it in an image viewer, you need to scale down the values with something like this -ot Byte -scale 0 65535 0 255 to keep all values, or you can cut at the maximum: -ot Byte -scale 0 35050 0 255.

But that will probably still be too dark, as your mean is 3832 and stddev is 4860, so you might even want -ot Byte -scale 0 16384 0 255. As you will then cut some high values, you will lose information in very bright spots like clouds and glaciers.


Related:

Related Question