Best way to merge color relief with shaded relief map

When creating a raster map featuring a shaded relief combined with elevation colors, then chances are that you are using the gdaldem tool to create both the hillshading (gdaldem hillshade) and the color relief map (gdaldem color-relief). But as soon as you have created both images, you might ask yourself how to combine both images into one. First, I want this to be reproducible in a script, so GIMP or Photoshop is not a viable option.

Let’s take a closer look at the results of some different methods I’ve tried out. The color relief and the hillshade relief images were created with the following commands:

$ gdalwarp -te 29 39 31 41 SRTM30.tif clip.tif
$ gdaldem color-relief clip.tif palette.cpt color.tif
$ gdaldem hillshade clip.tif hills.tif -z 3 -s 111120
Color relief

One option for combining these two images is the script from Frank Warmerdam. This script merges the two images in a way where the Hue and Saturation come from the color bands, and the Value comes from the panchromatic band.

But as stated here, “[this approach] works ok, but usually turns vegetation from a deep forest green to a minty pistachio green. This is because vegetation is very reflective in the IR band, which the pan band covers.” Let’s take a look at the result of

$ ./ color.tif hills.tif merged.tif
Result of

As you can see very clearly, the resulting image doesn’t match well with the original color relief in the lower green regions. I didn’t find this result satisfactory, so I looked into whether ImageMagick can be of help here.

A very simple operation would be

$ composite -blend 60 color.tif hills.tif output.tif

but the composite image looks, well, a bit gray (no surprise here):

Simple blend operation

A much better approach consists of two steps: adjusting the gamma level of the hillshade image so that the resulting gamma-corrected hillshade has the RGB value (128, 128, 128) in the plain areas, followed by a lighting composition. I’ve used the “overlay” method below, but you can also experiment with the other lighting methods available.

$ convert -gamma .5 hills.tif hills_gamma.tif
$ convert color.tif hills_gamma.tif -compose Overlay -composite output.tif
Gamma-corrected hillshade

Looks good doesn’t it? Note that the colors of the composite image match very well with the original color relief image.

Finally, note that applying any ImageMagick conversion leads to loosing the georeferencing in the TIFF image. To keep the georeferencing information, you can save the GeoTIFF metadata to a file, and then copy the metadata into a new image:

$ listgeo clip.tif > meta.txt
$ geotifcp -g meta.txt output.tif final.tif 

After this, final.tif should be georeferenced (you can check this with gdalinfo).

2 thoughts on “Best way to merge color relief with shaded relief map”

  1. It seems copying metadata is not sufficient for georeferenced images – no spatial coordinates are copied to the new image. To have a properly georeferenced image I had to produce ESRI World File (tfw):

    listgeo -tfw clip.tif

    and use in geotifcp:

    geotifcp -e clip.tfw output.tif final.tif

Leave a Reply