[GIS] get rgb images from sentinel-2 using gdal

gdal-mergergbsentinel-2sentinel-snap

i have some troubles to get RGB true colors image from sentinel satellite bands

enter image description here

wich produce this
enter image description here

to me it looks not natural at all

also i have tried gdal to do the merge with :

gdal_merge -o merged.tif -of GTIFF B04.jp2 B03.jp2 B02.jp2

but gave me an unusable file, at least in microDEM .

so i am wondering what's wrong here ?

Best Answer

You need to add the -separate option in order to place each input file into a separate band and (optionally) the -co PHOTOMETRIC=RGB creation option to force the photometric interpretation (to avoid e.g. the ColorInterp=undefined and set the right color interpretation for each band):

gdal_merge -separate -co PHOTOMETRIC=RGB -o merged.tif B04.jp2 B03.jp2 B02.jp2

Note: -of GTIFF is not necessary because GeoTIFF is the default output format.

Another approach consists into scaling the input bands before gdal_merging (but it's not strictly necessary in clients, where the bands are stretched):

for %%i in (4,3,2) do gdal_translate -scale B0%%i.jp2 B0%%i.tif
gdal_merge -separate -co PHOTOMETRIC=RGB -o merged.tif B04.tif B03.tif B02.tif

Finally the output needs some fine tuning operations, like the cut of histogram (e.g. a cumulative count cut) and the calibration of brightness, contrast and saturation, in order to be an acceptable RGB representation to use in GIS/RS clients or elsewhere. The following is a quick and dirty Sentinel-2 RGB sample created with gdal_merge and then visualized in QGIS:

enter image description here