lucem_ops::segment
Image segmentation: watershed, label post-processing, superpixels, random walker, and active contours.
watershed: marker-controlled floodingwatershedand Image Foresting Transformwatershed_ift.labels:expand_labels,clear_border,find_boundaries,mark_boundaries, andjoin_segmentations.superpixel:slic,felzenszwalb,quickshift, andrandom_walker.active_contour:chan_vese,morph_chan_vese,morph_geodesic_contour,checkerboard_level_set, anddisk_level_set.
ChanVeseOptions
Section titled “ChanVeseOptions”pub struct ChanVeseOptionsParameters for the Chan-Vese active contour model (chan_vese).
Fields
mu: f64lambda1: f64lambda2: f64tol: f64max_iter: usizedt: f64
Implements Clone, Debug, Default, PartialEq.
SlicOptions
Section titled “SlicOptions”pub struct SlicOptionsParameters for Simple Linear Iterative Clustering (slic).
Fields
n_segments: usizecompactness: f64max_iter: usize
Implements Clone, Debug, Default, PartialEq.
WatershedOptions
Section titled “WatershedOptions”pub struct WatershedOptionsOptions for marker-controlled watershed.
Fields
compactness: f64: Compact watershed weighting factor ($\ge 0$).0.0gives classic Meyer flooding.watershed_line: bool: Iftrue, keeps a 1-pixel dam (0) separating distinct catchment basins.
Implements Clone, Debug, Default, PartialEq.
BoundaryMode
Section titled “BoundaryMode”pub enum BoundaryModeBoundary localization mode for find_boundaries.
Variants
Thick: Both inner and outer boundary pixels around label transitions.Inner: Foreground pixels (!= background) adjacent to a different label.Outer: Pixels adjacent to a different foreground label.
Implements Clone, Copy, Debug, Default, Eq, PartialEq.
Functions
Section titled “Functions”checkerboard_level_set
Section titled “checkerboard_level_set”pub fn checkerboard_level_set<F: ImageFloat>( client: &Client, shape: Shape, square_size: usize,) -> OpsResult<DeviceArray<F>>Generates a 2-D checkerboard binary level-set (1.0 / 0.0) of shape = [h, w] with tile
size square_size on the device.
disk_level_set
Section titled “disk_level_set”pub fn disk_level_set<F: ImageFloat>( client: &Client, shape: Shape, center: Option<(f64, f64)>, radius: Option<f64>,) -> OpsResult<DeviceArray<F>>Generates a 2-D binary disk level-set (1.0 inside radius around center, 0.0 outside) on
the device. Defaults to the image center and 0.375 * min(h, w) when None.
chan_vese
Section titled “chan_vese”pub fn chan_vese<F: ImageFloat>( client: &Client, image: &DeviceArray<F>, init_level_set: Option<&DeviceArray<F>>, options: &ChanVeseOptions,) -> OpsResult<(DeviceArray<u32>, DeviceArray<F>)>Segments a 2-D image using the Chan-Vese active contour without edges, returning the binary
mask (1 where $\phi > 0$, 0 elsewhere) and the evolved level-set $\phi$.
morph_chan_vese
Section titled “morph_chan_vese”pub fn morph_chan_vese<F: ImageFloat>( client: &Client, image: &DeviceArray<F>, iterations: usize, init_level_set: Option<&DeviceArray<F>>, smoothing: usize, lambda1: f64, lambda2: f64,) -> OpsResult<DeviceArray<u32>>Morphological Active Contours Without Edges (MorphACWE / morph_chan_vese) on a 2-D image.
morph_geodesic_contour
Section titled “morph_geodesic_contour”pub fn morph_geodesic_contour<F: ImageFloat>( client: &Client, gimage: &DeviceArray<F>, iterations: usize, init_level_set: Option<&DeviceArray<F>>, smoothing: usize, threshold: f64, balloon: f64,) -> OpsResult<DeviceArray<u32>>Morphological Geodesic Active Contours (MorphGAC / morph_geodesic_contour) on a 2-D inverse
edge-indicator map gimage.
expand_labels
Section titled “expand_labels”pub fn expand_labels( client: &Client, labels: &DeviceArray<u32>, distance: f64, spacing: Option<&[f64]>,) -> OpsResult<DeviceArray<u32>>Dilates positive labels in labels into background (0) pixels by at most distance
Euclidean distance without overwriting existing labels, using
crate::core::distance::nearest_background_indices on the inverted foreground mask.
clear_border
Section titled “clear_border”pub fn clear_border( client: &Client, labels: &DeviceArray<u32>, buffer_size: usize, bgval: u32,) -> OpsResult<DeviceArray<u32>>Clears any labeled region (!= bgval) that touches the outer buffer_size-pixel border of
labels, setting those regions to bgval.
find_boundaries
Section titled “find_boundaries”pub fn find_boundaries( client: &Client, labels: &DeviceArray<u32>, connectivity: usize, mode: BoundaryMode, background: u32,) -> OpsResult<DeviceArray<u32>>Finds boundary pixels (1 on boundaries, 0 elsewhere) between distinct regions in a 2-D
labels array.
mark_boundaries
Section titled “mark_boundaries”pub fn mark_boundaries<F: ImageFloat>( client: &Client, image: &DeviceArray<F>, labels: &DeviceArray<u32>, color: [f64; 3], mode: BoundaryMode,) -> OpsResult<DeviceArray<F>>Returns an RGB [h, w, 3] visualization with boundaries of labels drawn in color on top of
a 2-D grayscale [h, w] or RGB [h, w, 3] image.
join_segmentations
Section titled “join_segmentations”pub fn join_segmentations( client: &Client, s1: &DeviceArray<u32>, s2: &DeviceArray<u32>,) -> OpsResult<DeviceArray<u32>>Computes the common refinement (overlay intersection) of two label maps s1 and s2,
sequentially relabeling every non-zero combined pair into 1..=num_joined.
pub fn slic<F: ImageFloat>( client: &Client, image: &DeviceArray<F>, options: &SlicOptions,) -> OpsResult<DeviceArray<u32>>Simple Linear Iterative Clustering (SLIC) superpixel over-segmentation on a 2-D image [h, w].
Runs each pixel-to-cluster assignment iteration on the device via slic_assign_2d_kernel.
felzenszwalb
Section titled “felzenszwalb”pub fn felzenszwalb<F: ImageFloat>( client: &Client, image: &DeviceArray<F>, scale: f64, min_size: usize,) -> OpsResult<DeviceArray<u32>>Graph-based minimum spanning forest segmentation (Felzenszwalb & Huttenlocher 2004) on a 2-D
image [h, w].
quickshift
Section titled “quickshift”pub fn quickshift<F: ImageFloat>( client: &Client, image: &DeviceArray<F>, kernel_size: f64, max_dist: f64, ratio: f64,) -> OpsResult<DeviceArray<u32>>Quickshift mode-seeking medoid shift segmentation (Vedaldi & Soatto 2008) on a 2-D image [h, w].
random_walker
Section titled “random_walker”pub fn random_walker<F: ImageFloat>( client: &Client, image: &DeviceArray<F>, markers: &DeviceArray<u32>, beta: f64, tol: f64, max_iter: usize,) -> OpsResult<DeviceArray<u32>>Anisotropic harmonic random-walker segmentation (Grady 2006) on a 2-D image [h, w] from
seed labels in markers (> 0 = seed label, 0 = unlabeled), using edge weights
$w_{ij} = \exp(-\beta (I_i - I_j)^2)$.
watershed
Section titled “watershed”pub fn watershed<F: ImageFloat>( client: &Client, relief: &DeviceArray<F>, markers: &DeviceArray<u32>, footprint: Option<&StructuringElement>, mask: Option<&DeviceArray<u32>>, options: &WatershedOptions,) -> OpsResult<DeviceArray<u32>>Marker-controlled watershed segmentation of an N-D topographic relief array starting from
positive seed labels in markers (0 = unlabeled), optionally restricted to non-zero pixels
of mask.
watershed_ift
Section titled “watershed_ift”pub fn watershed_ift<F: ImageFloat>( client: &Client, image: &DeviceArray<F>, markers: &DeviceArray<u32>, footprint: Option<&StructuringElement>,) -> OpsResult<DeviceArray<u32>>Image Foresting Transform (IFT) shortest-path watershed under the minimax path-cost
$f_{\max}(\pi) = \max_{e \in \pi} w(e)$ from positive seeds in markers.