lucem_pipeline
Pipeline engine of lucem: operators as typed graph nodes (ops), a graph evaluator over
image regions (eval), your own functions over images of any size (custom), pipelines as
data for headless runs (spec), and the older single-input modifier stack with live analytics
(modifier, executor).
RunOptions
Section titled “RunOptions”pub struct RunOptionsHow to walk an image.
Fields
level: usizechannels: Option<Vec<usize>>: Channels to process; all of them whenNone.walk: Walkblock: Option<usize>: Side of a block in y and x; the image’s tile size whenNone(at least 256).block_z: Option<usize>: Depth of a block inWalk::Volume; the image’s chunk depth whenNone(at least 32).halo: usize: Pixels of context on each side, in y and x.halo_z: Option<usize>: Planes of context on each side inWalk::Volume;halowhenNone.read_ahead: usize: Blocks read ahead of the one being processed.threads: usizecancel: Option<Arc<AtomicBool>>progress: Option<ProgressFn>
Methods
pub fn blocks(&self, py: &Pyramid) -> Result<(Zyx, Vec<Block>), RunError>The grid and the blocks of a walk.
Implements Clone, Default.
BlockContext
Section titled “BlockContext”pub struct BlockContextWhere a block sits, for the function that receives it.
Fields
index: usizetotal: usizelevel: usizechannel: usizeblock: Blockdownsample: f64: Level-0 pixels per pixel of this level.pixel_size_um: Option<f64>: Size of a pixel of this level (µm), if known.z_spacing_um: Option<f64>: Distance between planes of this level (µm), if known.
Implements Clone, Debug.
RunSummary
Section titled “RunSummary”pub struct RunSummaryWhat a headless run wrote.
Fields
output: PathBufspec: PathBuf: The spec, written next to the output.blocks: usizewarnings: Vec<String>objects: Option<usize>: Objects found (labels and tables).
Implements Clone, Debug.
PlanNode
Section titled “PlanNode”pub struct PlanNodeOne node of a plan.
Fields
op: Option<Op>:None: a source; its value comes from the caller.enabled: bool: Off: the node passes its first input through (when the types allow it).inputs: Vec<Option<String>>: The node feeding each input port.
Implements Clone, Debug.
PipelineExecutionResult
Section titled “PipelineExecutionResult”pub struct PipelineExecutionResultComplete output of evaluating the non-destructive GPU pipeline + analytics pass.
Fields
width: usizeheight: usizeoutput_host: Vec<f32>: Processed[height, width]image on the host for display tonemapping & pixel inspection.min_val: f64: Global min, max, mean, and std of the processed image.max_val: f64mean_val: f64std_val: f64otsu_level: f64entropy_bits: f64sharpness_score: f64hist_centers: Vec<f64>: 64-bin histogram counts and centers for the Analytics chart.hist_counts: Vec<u32>hist_df: DataFramecontours: Vec<Contour2d>: Marching Squares iso-contours at the Otsu threshold level (for VectorCraft contour overlay).regions: Vec<RegionFeatures>: Extracted connected-component region features + Polars DataFrame + Arrow RecordBatch.regions_df: DataFrameregions_batch: RecordBatchelapsed_ms: f64: Total GPU pipeline execution time in milliseconds.
Implements Clone, Debug.
PipelineExecutor
Section titled “PipelineExecutor”pub struct PipelineExecutorMethods
pub fn execute( client: &Client, input_dev: &DeviceArray<f32>, modifiers: &[ModifierNode], extract_contours: bool,) -> OpsResult<PipelineExecutionResult>Runs all enabled modifiers sequentially on input_dev on the GPU, then extracts
histogram, Marching Squares contours, and connected-component RegionFeatures into
Polars DataFrames and Arrow RecordBatches.
ModifierNode
Section titled “ModifierNode”pub struct ModifierNodeAn instance of a non-destructive GPU modifier in the Studio stack.
Fields
id: u64kind: ModifierKindenabled: boolprimary_param: f64secondary_param: f64
Methods
pub fn new(id: u64, kind: ModifierKind) -> SelfImplements Clone, Debug, Deserialize, PartialEq, Serialize.
SpecNode
Section titled “SpecNode”pub struct SpecNodeOne operator of a spec.
Fields
op: Opinputs: Vec<String>: The nodes or sources feeding each input port.enabled: bool
Implements Clone, Debug, Deserialize, JsonSchema, PartialEq, Serialize.
PipelineSpec
Section titled “PipelineSpec”pub struct PipelineSpecA pipeline to run over an image.
Fields
sources: BTreeMap<String, usize>: Source name to channel index.nodes: BTreeMap<String, SpecNode>target: String: The node whose result is written.level: usize: The pyramid level it runs on.normalize: bool: Scale each channel to 0–1 by its type’s range, as the app does.
Methods
pub fn plan(&self) -> PlanThe graph to evaluate.
pub fn validate(&self) -> Result<(), String>Names resolve, parameters are valid, ports are all connected and no node feeds itself.
Implements Clone, Debug, Deserialize, JsonSchema, PartialEq, Serialize.
LabelStitcher
Section titled “LabelStitcher”pub struct LabelStitcherProvisional ids, their joins and measurements. Add blocks in raster order.
Methods
pub fn new(grid: Zyx, link_z: bool) -> SelfFor blocks on a grid of grid ([z, y, x]). With link_z off, objects are joined within
each plane only (a walk plane by plane, where each plane was segmented by itself).
pub fn add(&mut self, block: &Block, labels: &[u32], intensity: Option<&[f32]>) -> Vec<u32>Adds the owned part of a block. labels holds its local labels (0: background) and
intensity, when given, the matching image, both C-ordered of block.size. Returns the
block with provisional ids.
Panics
Section titled “Panics”If the slices are not of the block’s size.
pub fn finish(self) -> StitchedJoins everything, numbers the objects 1, 2, … in order of first appearance and tabulates them. Positions are in the pixels of the level walked.
Implements Debug.
Stitched
Section titled “Stitched”pub struct StitchedThe final labels and a table of the objects.
Fields
map: Vec<u32>:map[provisional]is the final label (1, 2, …; 0 stays background).table: Table
Implements Clone, Debug.
pub struct TableA table of f64 columns (missing values are NaN).
Fields
columns: Vec<(String, Vec<f64>)>
Methods
pub fn new() -> Selfpub fn rows(&self) -> usizepub fn is_empty(&self) -> boolpub fn column(&self, name: &str) -> Option<&[f64]>The column called name.
pub fn push_row(&mut self, row: &[(String, f64)])Adds a row; a column not seen before is NaN in the earlier rows, and a column this row does not name is NaN in it.
pub fn to_frame(&self) -> PolarsResult<DataFrame>As a Polars frame, for analysis.
pub fn write_csv(&self, path: &Path) -> Result<()>Writes the table as CSV at path, which must not exist yet.
Implements Clone, Debug, Default, PartialEq.
RunError
Section titled “RunError”pub enum RunErrorVariants
Io(IoError)Function(String)Invalid(String)Cancelled
Implements Debug, Display, Error, From.
pub enum WalkHow a volume is walked (a 2D image has only planes).
Variants
Planes: Each plane by itself: the function gets[h, w].Volume: In 3D blocks: the function gets[d, h, w].
Implements Clone, Copy, Debug, Default, Eq, PartialEq.
ModifierKind
Section titled “ModifierKind”pub enum ModifierKindSupported non-destructive GPU operators in the Studio modifier stack and Node Editor.
Variants
GaussianBlurSobelEdgesClaheContrastGammaCurveTvChambolleDenoiseRollingBallBackgroundCannyEdgesOtsuThresholdMorphGradient
Methods
pub fn title(self) -> &'static strpub fn category(self) -> &'static strpub fn primary_label(self) -> &'static strpub fn default_params(self) -> (f64, f64)pub fn step(self) -> f64pub fn bounds(self) -> (f64, f64)Implements Clone, Copy, Debug, Deserialize, Eq, Hash, PartialEq, Serialize.
PortType
Section titled “PortType”pub enum PortTypeWhat flows along an edge.
Variants
Image: Intensities (f32, one channel).Mask: 0 / 1 per pixel.Labels: An object id per pixel (0: background).Table: One row per object (measurements).
Methods
pub fn name(self) -> &'static strImplements Clone, Copy, Debug, Deserialize, Eq, Hash, JsonSchema, PartialEq, Serialize.
pub enum ValueA value on the device (or, for tables, on the host).
Variants
Image(DeviceArray<f32>)Mask(DeviceArray<u32>)Labels(DeviceArray<u32>)Table(Vec<RegionFeatures>)
Methods
pub fn port(&self) -> PortTypepub fn dims(&self) -> Option<(usize, usize)>(height, width) of a raster value.
pub fn to_host(&self, client: &Client) -> Option<Vec<f32>>A raster value’s pixels as f32 on the host (labels as their ids, masks 0 / 1).
Implements Clone.
pub enum OpOne operator and its parameters.
Variants
GaussianBlur { sigma: f64 }: Gaussian smoothing.Median { radius: usize }: Median in a disk ofradiuspx.UnsharpMask { sigma: f64, amount: f64 }: Sharpening:x + amount · (x − blur(x)).DifferenceOfGaussians { low_sigma: f64, high_sigma: f64 }: Band-pass:blur(low) − blur(high)(blob enhancement).Sobel { }: Gradient magnitude.Laplace { }: Second derivative (edges, spots).Gamma { gamma: f64, gain: f64 }:gain · x^gamma(values in 0–1).Rescale { min: f64, max: f64 }: Maps[min, max]to[0, 1], clipped.Clahe { clip_limit: f64, tiles: usize }: Contrast-limited adaptive histogram equalization.RollingBall { radius: f64 }: Subtracts the rolling-ball background.TvDenoise { weight: f64, iterations: usize }: Total-variation denoising.WhiteTophat { radius: usize }: Bright details smaller than the disk (background removal).MorphGradient { radius: usize }: Dilation − erosion (outlines).Canny { sigma: f64 }: Edges as a mask.OtsuThreshold { bins: usize }: Pixels above the Otsu threshold.Threshold { value: f64 }: Pixels at or abovevalue.Open { radius: usize }: Mask opening (removes specks).Close { radius: usize }: Mask closing (fills gaps).Erode { radius: usize }Dilate { radius: usize }RemoveSmall { min_size: usize }: Drops objects smaller thanmin_sizepx.MaskUnion { }: On where A or B is on.MaskIntersect { }: On where A and B are on.MaskSubtract { }: On where A is on and B is off.MaskInvert { }: On where the mask is off.Label { }: Connected objects of a mask, numbered.Watershed { compactness: f64 }: Grows the marker labels over the relief image (splits touching objects).MaskImage { }: The image where the mask is on, 0 elsewhere.Combine { a: f64, b: f64 }:a · A + b · B.Measure { }: One row per labelled object: area, shape, intensity.
Methods
pub fn tag(&self) -> &'static strThe op tag (gaussian_blur, …).
pub fn title(&self) -> &'static strIts name for people.
pub fn family(&self) -> &'static strIts family (menus, colours).
pub fn inputs(&self) -> Vec<(PortType, &'static str)>Input types, in port order, with a name for each port.
pub fn output(&self) -> PortTypepub fn halo(&self) -> usizePixels of context read around each output pixel (at the level it runs on). Ops that look at the whole input (thresholds, CLAHE, labelling) give their usual margin; their result on a region can differ from the whole image’s.
pub fn at_downsample(&self, ds: f64) -> OpThe op for a level whose pixels are ds level-0 pixels: sizes (sigmas, radii, areas) are
given in level-0 px, so a result looks the same at every pyramid level.
pub fn is_global(&self) -> boolWhether its result depends on statistics of its whole input (so a region of the image needs the value computed on the whole image).
pub fn validate(&self) -> Result<(), String>Checks the parameters (positive sizes, finite numbers).
pub fn run(&self, client: &Client, inputs: &[Value]) -> Result<Value, String>Runs the op on its inputs (in port order, already type-checked by the caller).
Implements Clone, Debug, Deserialize, JsonSchema, PartialEq, Serialize.
pub type Plan = BTreeMap<String, PlanNode>;The graph to run, by node id.
Functions
Section titled “Functions”measure
Section titled “measure”pub fn measure<F>( client: &Client, py: &Arc<Pyramid>, options: &RunOptions, f: F,) -> Result<Table, RunError>where F: FnMut(&Client, &DeviceArray<f32>, &BlockContext) -> Result<Vec<(String, f64)>, String>Calls f on every block and gathers what it returns into a table, one row per block and
channel (with channel, z, y, x of the block).
transform
Section titled “transform”pub fn transform<F>( client: &Client, py: &Arc<Pyramid>, options: &RunOptions, output: &Path, f: F,) -> Result<PathBuf, RunError>where F: FnMut(&Client, &DeviceArray<f32>, &BlockContext) -> Result<DeviceArray<f32>, String>Writes f of every block to an OME-Zarr store at output (which must not exist), channel by
channel. f returns an array of the shape it was given.
segment
Section titled “segment”pub fn segment<F>( client: &Client, py: &Arc<Pyramid>, options: &RunOptions, output: &Path, f: F,) -> Result<Table, RunError>where F: FnMut(&Client, &DeviceArray<f32>, &BlockContext) -> Result<DeviceArray<u32>, String>Writes labels from f of every block of one channel to an OME-Zarr store at output (which
must not exist), joining objects cut by block borders, and returns one row per object. Labels
need not be numbered consistently between blocks. In Walk::Planes each plane’s objects are
separate; in Walk::Volume objects are joined along z too.
run_spec
Section titled “run_spec”pub fn run_spec( client: &Client, py: &Arc<Pyramid>, spec: &PipelineSpec, output: &Path, options: RunOptions,) -> Result<RunSummary, RunError>Runs a pipeline spec over an image, plane by plane: its target’s result is written to output
(OME-Zarr for images, masks and labels; CSV for tables), and the spec next to it.
evaluate
Section titled “evaluate”pub fn evaluate( client: &Client, plan: &Plan, target: &str, source: &mut dyn FnMut(&str) -> Result<Value, String>,) -> Result<Value, String>The value of target; source(id) gives each source node’s value.
evaluate_all
Section titled “evaluate_all”pub fn evaluate_all( client: &Client, plan: &Plan, targets: &[String], source: &mut dyn FnMut(&str) -> Result<Value, String>,) -> BTreeMap<String, Result<Value, String>>Every node of targets (and what they need), each computed once; a node that fails gives its
error and the others go on.
at_downsample
Section titled “at_downsample”pub fn at_downsample(plan: &Plan, ds: f64) -> PlanThe plan with every op set for a level of downsample ds (see Op::at_downsample).
pub fn halo(plan: &Plan, target: &str) -> usizePixels of context target needs around a region: the largest sum of halos on any path to a
source.
catalog
Section titled “catalog”pub fn catalog() -> Vec<Op>Every op with its default parameters, in menu order.
lucem_pipeline::custom
Section titled “lucem_pipeline::custom”Your own operations over an image of any size, built from lucem’s core methods.
ProgressFn
Section titled “ProgressFn”pub type ProgressFn = Arc<dyn Fn(usize, usize) + Send + Sync>;Called with blocks done and blocks in all.
DEFAULT_BLOCK_SIDE
Section titled “DEFAULT_BLOCK_SIDE”pub const DEFAULT_BLOCK_SIDE: usize = 1024;Default side of a block when the image’s chunks are not used.
lucem_pipeline::eval
Section titled “lucem_pipeline::eval”Runs a graph of ops: evaluate computes one node’s value from its inputs, recursively, each
node once (memoized), with the source rasters given by the caller (an image region, a mask
drawn by hand, …). The caller builds the plan from its own document, so this crate knows
nothing about projects or the app.
output_type
Section titled “output_type”pub fn output_type( plan: &Plan, id: &str, source_type: &dyn Fn(&str) -> Option<PortType>,) -> Option<PortType>What id gives (sources: source_type).