lucem_ops::intensity
Intensity conversions, contrast stretching, equalization, and stochastic noise synthesis.
ClaheSettings
Section titled “ClaheSettings”pub struct ClaheSettingsSettings for clahe (Contrast Limited Adaptive Histogram Equalization).
Fields
grid_size: (usize, usize): Number of contextual tiles(tiles_y, tiles_x). Default(8, 8).clip_limit: f64: Normalized clip limit in[0, 1]. Default0.01.num_bins: usize: Number of histogram bins per tile. Default256.
Implements Clone, Copy, Debug, Default.
IntensityRange
Section titled “IntensityRange”pub enum IntensityRangeInput range specification for rescale_range.
Variants
Image: Automatically stretch from the image’s minimum to maximum intensity on the device.Explicit(f64, f64): Stretch between explicit(min, max)bounds.
Implements Clone, Copy, Debug, PartialEq.
NoiseModel
Section titled “NoiseModel”pub enum NoiseModelNoise distribution model for add_noise.
Variants
Gaussian { mean: f64, std: f64 }: Additive Gaussian white noise with(mean, std).Speckle { mean: f64, std: f64 }: Multiplicative speckle noisex + x * N(mean, std^2).Salt { amount: f64 }: Impulse salt noise replacingamountfraction of pixels with1.0.Pepper { amount: f64 }: Impulse pepper noise replacingamountfraction of pixels with0.0.SaltAndPepper { amount: f64, salt_vs_pepper: f64 }: Impulse salt-and-pepper noise replacingamountfraction of pixels with1.0(salt_vs_pepper) or0.0.Poisson { scale: f64 }: Shot / Poisson noise scaled byscalephotons per unit intensity.
Implements Clone, Copy, Debug, PartialEq.
Functions
Section titled “Functions”rescale_range
Section titled “rescale_range”pub fn rescale_range<F: ImageFloat>( client: &Client, input: &DeviceArray<F>, in_range: IntensityRange, out_min: f64, out_max: f64,) -> OpsResult<DeviceArray<F>>Rescale image intensities from in_range into (out_min, out_max) on the device.
adjust_gamma
Section titled “adjust_gamma”pub fn adjust_gamma<F: ImageFloat>( client: &Client, input: &DeviceArray<F>, gamma: f64, gain: f64,) -> OpsResult<DeviceArray<F>>Power-law (gamma) transformation: gain * (x ^ gamma).
adjust_log
Section titled “adjust_log”pub fn adjust_log<F: ImageFloat>( client: &Client, input: &DeviceArray<F>, gain: f64, inv: bool,) -> OpsResult<DeviceArray<F>>Logarithmic intensity adjustment: gain * log2(1 + x) (or gain * (2^x - 1) when inv is true).
adjust_sigmoid
Section titled “adjust_sigmoid”pub fn adjust_sigmoid<F: ImageFloat>( client: &Client, input: &DeviceArray<F>, cutoff: f64, gain: f64, inv: bool,) -> OpsResult<DeviceArray<F>>Sigmoid contrast adjustment: 1 / (1 + exp(gain * (cutoff - x))).
is_low_contrast
Section titled “is_low_contrast”pub fn is_low_contrast<F: ImageFloat>( client: &Client, input: &DeviceArray<F>, fraction_threshold: f64, lower_percentile: f64, upper_percentile: f64,) -> OpsResult<bool>Determine whether an image has low contrast by comparing its [lower_percentile, upper_percentile]
intensity span to fraction_threshold of the dynamic range.
to_float
Section titled “to_float”pub fn to_float<Src: ImageInt, F: ImageFloat>( client: &Client, input: &DeviceArray<Src>, max_val: f64,) -> OpsResult<DeviceArray<F>>Convert an unsigned integer DeviceArray in 0..=max_val to a unit floating-point DeviceArray<F> in [0, 1].
pub fn to_u8<F: ImageFloat>( client: &Client, input: &DeviceArray<F>,) -> OpsResult<DeviceArray<u8>>Rescale a unit floating-point array in [0, 1] to u8 ([0, 255]) on the device.
to_u16
Section titled “to_u16”pub fn to_u16<F: ImageFloat>( client: &Client, input: &DeviceArray<F>,) -> OpsResult<DeviceArray<u16>>Rescale a unit floating-point array in [0, 1] to u16 ([0, 65535]) on the device.
to_u32
Section titled “to_u32”pub fn to_u32<F: ImageFloat>( client: &Client, input: &DeviceArray<F>, max_val: f64,) -> OpsResult<DeviceArray<u32>>Rescale a unit floating-point array in [0, 1] to u32 ([0, max_val]) on the device.
to_bool
Section titled “to_bool”pub fn to_bool<F: ImageFloat>( client: &Client, input: &DeviceArray<F>,) -> OpsResult<DeviceArray<u8>>Convert a floating-point array to a binary u8 mask (1 where x > 0, 0 otherwise).
invert
Section titled “invert”pub fn invert<F: ImageFloat>( client: &Client, input: &DeviceArray<F>, max_val: f64,) -> OpsResult<DeviceArray<F>>Invert a floating-point image around [0, max_val] (max_val - x).
pub fn crop<E: Numeric + CubeElement>( client: &Client, input: &DeviceArray<E>, crop_widths: &[(usize, usize)],) -> OpsResult<DeviceArray<E>>Crop [(before_0, after_0), ...] elements from each spatial axis of an N-D array (1-D, 2-D, or 3-D).
pub fn pad<F: ImageFloat>( client: &Client, input: &DeviceArray<F>, pad_widths: &[(usize, usize)], mode: PadMode, cval: f64,) -> OpsResult<DeviceArray<F>>Pad a floating-point array on each spatial axis according to pad_widths and mode.
cdf_device
Section titled “cdf_device”pub fn cdf_device<F: ImageFloat>( client: &Client, input: &DeviceArray<F>, num_bins: usize,) -> OpsResult<(DeviceArray<F>, DeviceArray<F>, DeviceArray<F>)>Compute the normalized cumulative distribution function (CDF) and device min/max bounds.
pub fn cdf<F: ImageFloat>( client: &Client, input: &DeviceArray<F>, num_bins: usize,) -> OpsResult<DeviceArray<F>>Compute the normalized cumulative distribution function (CDF) of an image ([num_bins]).
equalize_hist
Section titled “equalize_hist”pub fn equalize_hist<F: ImageFloat>( client: &Client, input: &DeviceArray<F>, num_bins: usize,) -> OpsResult<DeviceArray<F>>Global histogram equalization mapping intensities to [0, 1] via the device-computed CDF.
pub fn clahe<F: ImageFloat>( client: &Client, input: &DeviceArray<F>, settings: ClaheSettings,) -> OpsResult<DeviceArray<F>>Contrast Limited Adaptive Histogram Equalization (CLAHE) for 2-D images on the device.
match_histograms
Section titled “match_histograms”pub fn match_histograms<F: ImageFloat>( client: &Client, source: &DeviceArray<F>, reference: &DeviceArray<F>, num_bins: usize,) -> OpsResult<DeviceArray<F>>Match the histogram of source to that of reference on the device.
add_noise
Section titled “add_noise”pub fn add_noise<F: ImageFloat>( client: &Client, input: &DeviceArray<F>, model: NoiseModel, seed: u64, clip: bool,) -> OpsResult<DeviceArray<F>>Add synthetic random noise to an image on the device.