paralleldomain.utilities.mask¶
- boolean_mask_by_value(mask, value)¶
Returns a boolean mask where a specific value is inside the input mask.
- boolean_mask_by_values(mask, values)¶
Returns a boolean mask where specific values are inside the input mask.
- encode_2int16_as_rgba8(mask)¶
Encodes a mask with 2 16-bit values in a mask with 4 8-bit values.
- 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.
- 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.
- 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:
- 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.
- 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:
- Returns:
Returns array of shape (M x N x 1).