skimage2.util.map_array#

skimage2.util.map_array(input_arr, input_vals, output_vals, out=None)[source]#

Map values from input array from input_vals to output_vals.

Parameters:
input_arrarray of int, shape (M[, â€Ķ])

The input label image.

input_valsarray of int, shape (K,)

The values to map from.

output_valsarray, shape (K,)

The values to map to.

outarray, same shape as input_arr

The output array. Will be created if not provided. It should have the same dtype as output_vals.

Returns:
outarray, same shape as input_arr

The array of mapped values.

Notes

If input_arr contains values that aren’t covered by input_vals, they are set to 0.

Examples

>>> import numpy as np
>>> import _skimage2 as ski2
>>> ski2.util.map_array(
...    input_arr=np.array([[0, 2, 2, 0], [3, 4, 5, 0]]),
...    input_vals=np.array([1, 2, 3, 4, 6]),
...    output_vals=np.array([6, 7, 8, 9, 10]),
... )
array([[0, 7, 7, 0],
       [8, 9, 0, 0]])