lucem_ops::threshold
Global, adaptive local, and hysteresis thresholding.
LocalThreshold
Section titled “LocalThreshold”pub struct LocalThresholdSettings for local_threshold.
Fields
method: LocalMethodoffset: f64: Constant subtracted from the local weighted average (T(x) = local_stat(x) - offset).mode: PadModecval: f64
Implements Clone, Debug, Default, PartialEq.
WindowThreshold
Section titled “WindowThreshold”pub struct WindowThresholdSettings for niblack and sauvola local thresholding.
Fields
window_size: usizek: f64r: f64: Dynamic range of standard deviation (used by Sauvola; defaults to0.5for float images).mode: PadModecval: f64
Implements Clone, Debug, Default, PartialEq.
LocalMethod
Section titled “LocalMethod”pub enum LocalMethodMethod for computing the local reference surface in local_threshold.
Variants
GaussianMeanMedian
Implements Clone, Copy, Debug, Default, Eq, PartialEq.
Functions
Section titled “Functions”otsu_device
Section titled “otsu_device”pub fn otsu_device<F: ImageFloat>( client: &Client, input: &DeviceArray<F>, nbins: usize,) -> OpsResult<DeviceArray<F>>Computes the Otsu threshold on the device as a 1-element DeviceArray<F>.
pub fn otsu<F: ImageFloat>( client: &Client, input: &DeviceArray<F>, nbins: usize,) -> OpsResult<f64>Computes the global Otsu threshold maximizing inter-class variance.
multi_otsu
Section titled “multi_otsu”pub fn multi_otsu<F: ImageFloat>( client: &Client, input: &DeviceArray<F>, classes: usize, nbins: usize,) -> OpsResult<Vec<f64>>Multi-class Otsu thresholding for classes classes (classes >= 2), returning classes - 1
sorted thresholds maximizing between-class variance via dynamic programming over the histogram.
mean_threshold_device
Section titled “mean_threshold_device”pub fn mean_threshold_device<F: ImageFloat>( client: &Client, input: &DeviceArray<F>,) -> OpsResult<DeviceArray<F>>Global mean threshold as a 1-element DeviceArray<F>.
mean_threshold
Section titled “mean_threshold”pub fn mean_threshold<F: ImageFloat>(client: &Client, input: &DeviceArray<F>) -> OpsResult<f64>Global mean threshold.
isodata
Section titled “isodata”pub fn isodata<F: ImageFloat>( client: &Client, input: &DeviceArray<F>, nbins: usize,) -> OpsResult<f64>ISODATA iterative threshold ($\theta = \frac{1}{2}(\mu_0(\theta) + \mu_1(\theta))$).
isodata_device
Section titled “isodata_device”pub fn isodata_device<F: ImageFloat>( client: &Client, input: &DeviceArray<F>, nbins: usize,) -> OpsResult<DeviceArray<F>>ISODATA threshold on the device.
pub fn li<F: ImageFloat>( client: &Client, input: &DeviceArray<F>, nbins: usize,) -> OpsResult<f64>Li’s iterative minimum cross-entropy threshold.
li_device
Section titled “li_device”pub fn li_device<F: ImageFloat>( client: &Client, input: &DeviceArray<F>, nbins: usize,) -> OpsResult<DeviceArray<F>>Li threshold as a 1-element DeviceArray<F>.
pub fn yen<F: ImageFloat>( client: &Client, input: &DeviceArray<F>, nbins: usize,) -> OpsResult<f64>Yen’s maximum correlation criterion threshold.
yen_device
Section titled “yen_device”pub fn yen_device<F: ImageFloat>( client: &Client, input: &DeviceArray<F>, nbins: usize,) -> OpsResult<DeviceArray<F>>Yen threshold as a 1-element DeviceArray<F>.
triangle
Section titled “triangle”pub fn triangle<F: ImageFloat>( client: &Client, input: &DeviceArray<F>, nbins: usize,) -> OpsResult<f64>Geometric triangle threshold: constructs a chord from the histogram peak to the farthest non-zero tail and picks the bin at maximum perpendicular distance.
triangle_device
Section titled “triangle_device”pub fn triangle_device<F: ImageFloat>( client: &Client, input: &DeviceArray<F>, nbins: usize,) -> OpsResult<DeviceArray<F>>Triangle threshold as a 1-element DeviceArray<F>.
minimum_threshold
Section titled “minimum_threshold”pub fn minimum_threshold<F: ImageFloat>( client: &Client, input: &DeviceArray<F>, nbins: usize, max_num_iter: usize,) -> OpsResult<f64>Bimodal minimum threshold: iteratively smooths the histogram with a 3-point moving average until at most two local maxima remain, then returns the valley minimum between them.
hysteresis_threshold
Section titled “hysteresis_threshold”pub fn hysteresis_threshold<F: ImageFloat>( client: &Client, input: &DeviceArray<F>, low: f64, high: f64,) -> OpsResult<DeviceArray<u32>>Applies hysteresis thresholding with low and high thresholds: pixels > high are strong
foreground, and pixels > low connected (with full connectivity) to at least one strong pixel
are retained (1u32, else 0u32).
local_threshold_into
Section titled “local_threshold_into”pub fn local_threshold_into<F: ImageFloat>( client: &Client, input: &DeviceArray<F>, block_size: usize, output: &DeviceArray<F>, settings: &LocalThreshold, ws: &mut Workspace,) -> OpsResult<()>Computes the local adaptive threshold surface $T(x) = \text{local_stat}(x) - \text{offset}$
over windows of side block_size into output.
local_threshold
Section titled “local_threshold”pub fn local_threshold<F: ImageFloat>( client: &Client, input: &DeviceArray<F>, block_size: usize, settings: &LocalThreshold,) -> OpsResult<DeviceArray<F>>Allocates and returns the local adaptive threshold surface.
niblack_into
Section titled “niblack_into”pub fn niblack_into<F: ImageFloat>( client: &Client, input: &DeviceArray<F>, output: &DeviceArray<F>, settings: &WindowThreshold, ws: &mut Workspace,) -> OpsResult<()>Niblack local threshold surface $T = \mu - k \sigma$ into output.
niblack
Section titled “niblack”pub fn niblack<F: ImageFloat>( client: &Client, input: &DeviceArray<F>, settings: &WindowThreshold,) -> OpsResult<DeviceArray<F>>Niblack local threshold surface allocating output.
sauvola_into
Section titled “sauvola_into”pub fn sauvola_into<F: ImageFloat>( client: &Client, input: &DeviceArray<F>, output: &DeviceArray<F>, settings: &WindowThreshold, ws: &mut Workspace,) -> OpsResult<()>Sauvola local threshold surface $T = \mu \cdot \left(1 + k \left(\frac{\sigma}{R} - 1\right)\right)$
into output.
sauvola
Section titled “sauvola”pub fn sauvola<F: ImageFloat>( client: &Client, input: &DeviceArray<F>, settings: &WindowThreshold,) -> OpsResult<DeviceArray<F>>Sauvola local threshold surface allocating output.