The Wrong Side of my Car

The blog that wants to go obsolete

6 Apr 2018

Making the relief map: the base

If you download a DEM it looks roughly like this:

By itself, visualizing relief as a greyscale image has an advantage: the eye is quite sensitive to changes in brightness, making it a good choice if you want to discover fine details in the image. But I wanted to overlay a street map over the relief, and doing this in a clear manner is really hard if the background varies between black and white.

So what I want to do is 2 things:

Calculating relief shading

Relief shading in its most basic form means rendering the DEM as if it’s a 3D surface, lit by a directional light source, usually from the top left.

An easy way to get relief shading is with ImageMagick *1:

convert example.exr -blur 0x2 +level 1%%,30%% -gamma .4545 ^
    -shade 135x60 ^
    +level 45%%,100%% -colorspace sRGB example-shade.png

A minimal command would only need the -shade flag, but the others add some level corrections so we can tune the result. The -colorspace command makes sure the image is written in a way which most programs understand (i.e. not in linear space, but in the much more common sRGB space).

Doing this on tiles is tricky, as you’ll end up with seams if there’s steep relief near the edges. You can overlap the tiles a bit and crop away the extra edges afterwards to avoid this.

Creating the colors

The shaded map above gives a nice idea of the local relief in the areas, however it’s hard to make out the larger scale relief. For that we will map the height to a color gradient. Choosing such a gradient is a compromise between making it prominent enough to easily see the colors, versus making sure our street map overlay still stands out.

A popular choice to denote height in physical maps is green for low-lying areas via yellow, to red for higher areas. Pick some colors, and then create some gradients, right? This is one of these things which are sometimes called deceptively simple.

Actually, choosing a palette which maps similar differences in height to similarly different-looking colors is notoriously difficult, especially with palettes which cycle through more than a pair of colors. Entire series of blog posts are devoted to this topic.

A starting point to pick a more uniform palette is to define a color space where distances between color values are more closely related to perceptual differences. Examples are the CIE Lab* space and the related HCL space. The usual HSV color space is especially bad. Tristen Brown created an HCL color picker based on Gregor Aisch’s article which I used to create a palette ranging from green to purplish red. To the right I added an extra gradient towards white to cover the higher elevation of the Waitakere Ranges.

So let’s apply our color map to the DEM. 100 m is mapped to the reddish color:

Combine this with our relief shaded map for the final result:

This as well can be done using ImageMagick:

convert example.exr +level 0,1000% ^
    palette.png -clut ^
    example-shade.png -compose multiply -composite ^
    example-final.png

And this forms the base for our relief map.


(*1) 

For some unfathomable reason, most image processing libraries will occasionally clamp HDR images to the 0–1 range. This is quite annoying since a DEM often contains elevation values in metres. One way to avoid running into problems is to scale the values down, in this example the input image was scaled to use the kilometre as unit.

No comments

Post a Comment