Relief Shading
Multiplicative relief shading is provided via
relief_shading(). This technique can notably enhance the
perception of shape induced by the shading:
This example uses relief shading with different color maps to show
the topographic structure of (a small part of) the lunar farside, which
was captured by the Lunar Reconnaissance Orbiter in 2011 and published by
NASA/GSFC/Arizona State University.
The smaller images below each main visualization show the inputs to
relief_shading(), i.e. the relief and its false color
representation.
Note how the two isoluminant relief color maps are not useful on their own, but
induce a proper shape perception after shading.
Python code for this visualization example:
1moon_full = viren2d.load_image_uint8(VIREN2D_DATA_PATH / 'lunar-farside.jpg')
2moon = moon_full.roi(left=200, top=200, width=200, height=200)
3
4cmap_names = ['Earth', 'Relief', 'Relief Low Contrast']
5
6column_width = (cwidth - (len(cmap_names) * 10)) / len(cmap_names)
7scale = column_width / moon.width
8
9x = column_width / 2 + 5
10for cmap_name in cmap_names:
11 # Show the color bar on top of the shaded relief:
12 colorbar = viren2d.colorize_scaled(
13 data=colorbar_data, colormap=cmap_name, low=0, high=255)
14
15 painter.draw_image(
16 colorbar, position=(x, 15), anchor='center',
17 clip_factor=0.5, scale_x=column_width/colorbar.width)
18
19 painter.draw_text(
20 [cmap_name], position=(x, 15), anchor='center',
21 text_style=text_style)
22
23 # Colorize & shade the relief of the farside of the moon:
24 vis = viren2d.colorize_scaled(
25 data=moon, colormap=cmap_name)
26
27 relief = viren2d.relief_shading(relief=moon, colorized=vis)
28
29 painter.draw_image(
30 relief, position=(x, 35), anchor='top', clip_factor=1,
31 scale_x=scale, scale_y=scale)
32
33 # Also show the inputs to relief shading:
34 painter.draw_image(
35 moon, position=(x - 20, cheight - 5), anchor='bottom-right',
36 clip_factor=1, scale_x=scale / 3, scale_y=scale / 3)
37
38 painter.draw_image(
39 vis, position=(x + 20, cheight - 5), anchor='bottom-left',
40 clip_factor=1, scale_x=scale / 3, scale_y=scale / 3)
41
42 # Draw a marker that looks like element-wise matrix multiplication:
43 pos_multiplier = (x, cheight - 5 - moon.width * scale / 6)
44 painter.draw_marker(
45 position=pos_multiplier,
46 marker_style=viren2d.MarkerStyle('.', size=23, color='ivory'))
47 painter.draw_marker(
48 position=pos_multiplier,
49 marker_style=viren2d.MarkerStyle('o', size=18, color='black', thickness=2))
50 painter.draw_marker(
51 position=pos_multiplier,
52 marker_style=viren2d.MarkerStyle('x', size=12, color='black', thickness=2))
