Skip to main content

find_objects_2d

Function find_objects_2d 

Source
pub fn find_objects_2d(
    labeled: &ArrayBase<OwnedRepr<usize>, Dim<[usize; 2]>>,
) -> Result<Vec<BoundingBox2D>, NdimageError>
Expand description

Find objects (bounding boxes) in a 2D labeled image

Returns a BoundingBox2D for each unique non-zero label in the input. The bounding boxes are sorted by label value.

§Arguments

  • labeled - 2D labeled array where 0 = background

§Returns

  • Result<Vec<BoundingBox2D>> - Bounding boxes sorted by label

§Example

use scirs2_core::ndarray::array;
use scirs2_ndimage::morphology::{label_2d, find_objects_2d};

let input = array![
    [true, true, false, false],
    [true, true, false, false],
    [false, false, true, true],
    [false, false, true, true],
];

let (labeled, _) = label_2d(&input, None).expect("label_2d should succeed");
let objects = find_objects_2d(&labeled).expect("find_objects_2d should succeed");
assert_eq!(objects.len(), 2);