paralleldomain.utilities.mask

boolean_mask_by_value(mask, value)

Returns a boolean mask where a specific value is inside the input mask.

Parameters:
  • mask (ndarray) – Array of shape (M x N x 1). All values must be of type int.

  • value (int) – A single value to be masked as True

Return type:

ndarray

Returns:

Returns array of shape (M x N x 1).

boolean_mask_by_values(mask, values)

Returns a boolean mask where specific values are inside the input mask.

Parameters:
  • mask (ndarray) – Array of shape (M x N x 1). All values must be of type int.

  • values (List[int]) – A list of values to be masked as True

Return type:

ndarray

Returns:

Returns array of shape (M x N x 1).

encode_2int16_as_rgba8(mask)

Encodes a mask with 2 16-bit values in a mask with 4 8-bit values.

Parameters:

mask (ndarray) – Array of shape (M x N x 2). Note: Values are assumed to be 16-bit integers.

Return type:

ndarray

Returns:

Returns array of shape (M x N x 4).

encode_int32_as_rgb8(mask)
Encodes a mask with 1 32-bit value in a mask with 3 8-bit values by truncating the highest 8 bits. Used to

convert a single value color representation into an RGB array.

Parameters:

mask (ndarray) – Array of shape (M x N x 1). Note: Values are assumed to be 32-bit integers.

Return type:

ndarray

Returns:

Returns array of shape (M x N x 4).

encode_rgb8_as_int32(mask)
Encodes a mask with 3 8-bit values in a mask with 1 32-bit value. Used to convert an RGB array into a single

value color representation.

Parameters:

mask (ndarray) – Array of shape (M x N x 3). Note: Values are assumed to be 8-bit integers.

Return type:

ndarray

Returns:

Returns array of shape (M x N x 1).

lookup_values(mask, x, y, interpolate=False)

Executes bilinear interpolation on a 2D plane.

Parameters:
  • mask (ndarray) – Array of shape (M x N [x L]). Note: If 3 dimensions are provided, bilinear interpolation is performed on each 2D plane in the first two dimensions.

  • x (Union[ndarray, List]) – List of indices to interpolate on along the x-axis (columns). Indices < 0 and > (M-1, N-1) will be clipped to 0 or (M-1, N-1), respectively.

  • y (Union[ndarray, List]) – List of indices to interpolate on along the y-axis (rows). Indices < 0 and > (M-1, N-1) will be clipped to 0 or (M-1, N-1), respectively.

  • interpolate (bool) –

Return type:

ndarray

Returns:

Returns interpolated values for input (x,y) as array with shape (len(x) [x L]).

replace_value(mask, old_value, new_value)

Replaces values in a mask by a new value.

Parameters:
  • mask (ndarray) – Array of shape (M x N x 1). All values must be of type int.

  • old_value (int) – Source value to be replaced.

  • new_value (int) – Target value to be replaced with.

Return type:

ndarray

Returns:

Returns array of shape (M x N x 1).

replace_values(mask, value_map, value_min=None, value_max=None)

Replaces values in a mask by new values.

Parameters:
  • mask (ndarray) – Array of shape (M x N x 1). All values must be of type int.

  • value_map (Dict[int, int]) – Dictionary of source and target values. Source values will be replaced by target values.

  • value_min (Optional[int]) – If known beforehand, setting the minimum allowed value will make processing faster. Otherwise, inferred by mask’s dtype.

  • value_max (Optional[int]) – If known beforehand, setting the maximum allowed value will make processing faster. Otherwise, inferred by mask’s dtype.

Return type:

ndarray

Returns:

Returns array of shape (M x N x 1).