ColorMap

Maps a scalar field to a color field using a color map.

Maps a scalar field to a color field using a color map.

The color maps are generated using Matplotlib available color maps as:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
import numpy as np
import matplotlib as mpl
import base64

colormap_names = ['viridis', 'plasma', 'inferno', 'magma', 'cividis', 'gray', 'Purples', 'Blues', 'Greens', 'Oranges', 'Reds', 'Spectral', 'coolwarm', 'bwr', 'seismic', 'twilight', 'hsv']

x = np.linspace(0, 1, 256)

for name in colormap_names:
    
    cmap = mpl.colormaps[name]
    RGB = cmap(x)
    
    RGBA = [[c[0], c[1], c[2], 0] for c in RGB]
    RGBA = np.ceil(np.array(RGBA) * 255).astype(np.uint8)
    
    data = RGBA.data.tobytes()
    s = str(base64.b64encode(data), 'utf-8')
    
    lua_str = "builder.colorMaps['{0}'] = '{1}'".format(name.lower(), s)
    print(lua_str)

Parameters

color_map : string. Defaults to “viridis”. The color map to use. Possible values are:

Perceptually uniform maps:

- viridis
- plasma
- inferno
- magma
- cividis

Sequential maps:

- gray
- purples
- blues
- greens
- oranges
- reds

Diverging maps:

- spectral
- coolwarm
- bwr
- seismic

Cyclic maps:

- twilight
- hsv

min_value : float. Defaults to 0.0. The minimum value of the input image.

max_value : float. Defaults to 1.0. The maximum value of the input image.

alpha : float. Defaults to 0.0. The alpha value of the output image in range [0, 1].

reverse: float. Defaults to 0.0. If 1.0, the color map is reversed.

Inputs

in_image : ImageView. {r8ui, r8i, r16f, r32f} image. Input image.

Outputs

out_image : ImageView rgba8ui image. The encoded color of the optical flow field.