1

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.

  • 1
    ArcMap automatically applies a stretch to your raster, I think the default for RGB is percent clip, if the resulting image is still detected to be dark a gamma is also applied... look at your symbology tab in ArcMap and note the settings. If you want to see the image like it is in ArcMap in a picture viewer you can export it using renderer to 'brighten up' the image. – Michael Stimson Jul 24 '18 at 23:06
3

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:

  • Thanks, I will try this out and get back to the thread with results. Is that true that 98% of values lie between 20 and 150 (as a general rule of thumb)? – jonesy19 Jul 26 '18 at 3:40
  • No not at all.That is individual – pLumo Jul 26 '18 at 4:41
  • Hmm...So using the command you referenced above, it creates a new tif, but the tif file is completely white. I ran the gdalinfo -hist command, and it gave me three sets of answers (I'm guessing one for each colorband). There's a lot of info on the output, however. What values from this output are the values that you are referencing in your answer? Should I be looking here? Metadata: STATISTICS_MAXIMUM=35050 STATISTICS_MEAN=3832.5215314015 STATISTICS_MINIMUM=0 STATISTICS_STDDEV=4860.9555695374 Band 3 Block=9697x1 Type=UInt16, ColorInterp=Blue Thanks! – jonesy19 Jul 26 '18 at 17:35
  • What do you mean by the tif file is completely white ? The tif file has values not colors, the program you open the file with "decides" which value is which color. You need to scale the values to mach a "normal" 8 bit image, I updated the answer. – pLumo Jul 27 '18 at 7:18
  • Thanks so much for the updated answer. Although your numbers gave me a completely black picture, it put me on the right track. I used the following value "-ot Byte -scale 0 150 0 255", and it gave me a nice bright image. You don't have to respond, as I've got what I need, but out of curiosity - do you know why that number worked? If I go with a higher number, it starts to get darker and darker. Thanks! – jonesy19 Aug 2 '18 at 19:45

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.