pub fn segmentation_to_mask(
segmentation: ArrayView3<'_, u8>,
) -> Result<Array2<u8>, DecoderError>Expand description
Converts a segmentation tensor into a 2D mask If the last dimension of the segmentation tensor is 1, values equal or above 128 are considered objects. Otherwise the object is the argmax index
§Errors
Returns DecoderError::InvalidShape if the segmentation tensor has an
invalid shape.
§Examples
let segmentation =
ndarray::Array3::<u8>::from_shape_vec((2, 2, 1), vec![0, 255, 128, 127]).unwrap();
let mask = segmentation_to_mask(segmentation.view()).unwrap();
assert_eq!(mask, ndarray::array![[0, 1], [1, 0]]);