Writing @lucem.op tiled filters
@lucem.op(family="Filter", halo=12) turns a standard NumPy / SciPy function into a halo-aware tiled
operator that works identically in Python scripts and inside the Lucem app’s Pipeline and
Code workspaces:
import numpy as npfrom scipy.ndimage import gaussian_filterimport lucem
@lucem.op(family="Filter", halo=12)def local_contrast_boost( image: np.ndarray, sigma: float = 3.0, strength: float = 1.8,) -> np.ndarray: """Enhance fine cellular structures by subtracting a blurred local background.""" img = image.astype(np.float32, copy=False) bg = gaussian_filter(img, sigma=max(float(sigma), 0.2)) enhanced = img + float(strength) * (img - bg) return np.clip(enhanced, float(img.min()), float(img.max())).astype(np.float32)Verify tiled execution matches whole-image execution across tile borders
img = lucem.io.open(zarr_path)tiled = local_contrast_boost.apply(img, sigma=3.0, strength=1.8)whole = local_contrast_boost(src, sigma=3.0, strength=1.8)
assert np.max(np.abs(tiled[16:-16, 16:-16] - whole[16:-16, 16:-16])) < 1e-3The whole script is playground/05_custom_ops/01_lucem_op_decorator.py. Run it with uv run python playground/05_custom_ops/01_lucem_op_decorator.py.