Skip to content

Estimates

The model-sized results shared by estimators, simulators and corrections, and the conventions they follow (which are also explained in Image formation and noise).

Model-sized results shared by estimators, simulators and corrections.

Conventions
  • Every field is a Tensor (or None) that broadcasts against the spatial shape. None means "not estimated": consumers fall back to their own default, never silently to zero.
  • ShadingEstimate.dark is the whole additive image of x = (y - dark) / flat - baseline: it includes the camera offset.
  • ShadingEstimate.baseline is in signal units, inside the flat (y = f ⊙ (x + bₙ) + d), unless meta["baseline_units"] == "raw" (y = f · x + d + bₙ, outside the flat). SensorEstimate.offset is the camera offset alone. A model with a single additive term returns it in both; corrections never subtract both.
  • Gains are in ADU per electron (EMVA 1288 K).
  • Flat fields are stored as produced by the algorithm; meta["flat_norm"] records the normalisation ("mean" or "geomean") and ShadingEstimate.normalize converts.
  • PSFEstimate.psf is normalised to unit sum and centred at index K // 2 along each spatial axis, as the PSFs taken by optix.deconv.
  • TileIntensityEstimate maps the recorded tile to the harmonised one, x̂ = scale · y + shift, one pair per tile (and group).
  • Data-sized outputs (class probabilities, corrected stacks) are never stored in an estimate: they come from Estimator.apply(data, out=).

Estimate dataclass

Estimate(*, meta=dict())

Base for model-sized results. Fields are tensors or None.

Numbers given for tensor fields are converted to 0-d tensors.

Attributes:

Name Type Description
meta dict

Provenance and conventions (estimator class, optix version, resolved options, faithful, units, flat_norm...). Must be JSON-serialisable.

to

to(device=None, dtype=None)

Return a copy on device; dtype casts floating fields only.

Boolean masks and integer fields keep their dtype.

clone

clone()

Deep copy (tensors cloned, meta deep-copied).

replace

replace(**changes)

Copy with some fields replaced (dataclasses.replace).

allclose

allclose(other, **tol)

Same type, same estimated fields, and torch.allclose values.

Parameters:

Name Type Description Default
other Estimate
required
**tol float

rtol / atol / equal_nan for torch.allclose. meta is not compared.

{}

to_dict

to_dict()

Fields and meta as a plain dict (write it where you like).

from_dict classmethod

from_dict(d)

Inverse of to_dict.

save

save(path)

Save with torch.save (no pickled classes).

Raises:

Type Description
TypeError

If meta is not JSON-serialisable.

load classmethod

load(path)

Load an estimate saved with save.

Loading uses weights_only.

SensorEstimate dataclass

SensorEstimate(offset=None, variance=None, gain=None, defective=None, *, meta=dict())

Bases: Estimate

Camera model y = offset + gain * e + ε.

e ~ Poisson(electrons) and ε ~ N(0, variance). The Foi et al. (2008) parametrisation is derived, not stored: a = gain, b = variance - gain * offset.

References

  1. Foi A, Trimeche M, Katkovnik V, Egiazarian K. Practical Poissonian-Gaussian noise modeling and fitting for single-image raw-data. IEEE Trans Image Process 17(10):1737–1754, 2008. doi:10.1109/TIP.2008.2001399
BibTeX
@article{foi2008practical,
  author  = {Foi, Alessandro and Trimeche, Mejdi and
             Katkovnik, Vladimir and Egiazarian, Karen},
  title   = {Practical {Poissonian-Gaussian} noise modeling
             and fitting for single-image raw-data},
  journal = {IEEE Transactions on Image Processing},
  volume  = {17},
  number  = {10},
  pages   = {1737--1754},
  year    = {2008},
  doi     = {10.1109/TIP.2008.2001399}
}

Attributes:

Name Type Description
offset (Tensor, optional)

Camera offset in ADU; scalar or (H, W).

variance (Tensor, optional)

Read-noise variance in ADU².

gain (Tensor, optional)

ADU per electron; scalar or (H, W).

defective (Tensor, optional)

Boolean (H, W) map, True = unusable pixel.

noise_variance

noise_variance(mean)

Variance of the data at a given mean signal (ADU).

Parameters:

Name Type Description Default
mean Tensor

Expected value of y (ADU).

required

Returns:

Type Description
Tensor

variance + gain * (mean - offset).

ShadingEstimate dataclass

ShadingEstimate(flat=None, dark=None, baseline=None, *, meta=dict())

Bases: Estimate

Shading model with a per-frame baseline.

The baseline bₙ is a scalar per frame, in one of two units, recorded in meta["baseline_units"]:

  • "signal" (default, also when the key is absent): an offset of the signal before shading, so that it is shaded too, y = f ⊙ (x + bₙ) + d (as in BaSiC).
  • "raw": an offset of the measured frame, y = f · x + d + bₙ.

The two agree only for a uniform flat field: a signal baseline bₙ is the raw offset f · bₙ, which is not a scalar.

Attributes:

Name Type Description
flat (Tensor, optional)

(H, W) multiplicative flat field.

dark (Tensor, optional)

(H, W) total additive term in ADU (includes the camera offset).

baseline (Tensor, optional)

(*batch, frames) per-frame offset, in baseline_units.

baseline_units property

baseline_units

meta["baseline_units"]: "signal" (the default) or "raw".

shade

shade(x, baseline=None, *, units=None)

Apply the model to a signal x of shape (*batch, frames, H, W).

Parameters:

Name Type Description Default
x Tensor

Unshaded signal.

required
baseline Tensor

(*batch, frames) baseline to use instead of self.baseline.

None
units (signal, raw)

Units of the baseline (default: baseline_units).

"signal"

Returns:

Type Description
Tensor

f ⊙ (x + bₙ) + d (signal) or f · x + d + bₙ (raw). Fields that are None are absent terms (f = 1, d = 0, bₙ = 0).

correct

correct(y, baseline=None, *, units=None, norm=0.0)

Invert the model for frames y of shape (*batch, frames, H, W).

Parameters:

Name Type Description Default
y Tensor

Measured frames.

required
baseline Tensor

(*batch, frames) baseline to use instead of self.baseline.

None
units (signal, raw)

Units of the baseline (default: baseline_units).

"signal"
norm Tensor or float

Background added back, in the units of the baseline (broadcasts against baseline).

0.0

Returns:

Type Description
Tensor

(y − d) / f − (bₙ − norm) (signal) or (y − d − (bₙ − norm)) / f (raw).

normalize

normalize(mode='mean')

Rescale the flat field so that its mean (or geometric mean) is 1.

With c the mean (or geometric mean) of the flat, the flat becomes f / c and the scale c moves into the signal: x̂ = c · x. The dark is unchanged. The baseline bₙ becomes c · bₙ when baseline_units == "signal" (y = f ⊙ (x + bₙ) + d), and is unchanged when it is "raw" (y = f · x + d + bₙ), so that shade and correct stay consistent with x̂. A baseline norm derived from the baseline (BaSiC's baseline_norm="mean") follows automatically; a numeric norm passed to correct is in the units of the (rescaled) baseline.

Parameters:

Name Type Description Default
mode (mean, geomean)
"mean"

Returns:

Type Description
ShadingEstimate

Copy with the rescaled flat (and signal-units baseline) and meta["flat_norm"] = mode.

Classification dataclass

Classification(weights=None, parameters=None, concentration=None, *, meta=dict())

Bases: Estimate

Class model summary (provisional).

Per-voxel probabilities are data-sized and come from apply(data, out=); only the class model is stored here.

Attributes:

Name Type Description
weights (Tensor, optional)

(K,) mixing weights.

parameters (Tensor, optional)

(K, P) class parameters (meaning recorded in meta).

concentration (Tensor, optional)

(K,) Dirichlet concentration of the mixing weights, for models that treat them as uncertain (weights is then its mean).

PSFEstimate dataclass

PSFEstimate(psf=None, fwhm=None, count=None, centers=None, *, meta=dict())

Bases: Estimate

Empirical point spread function, with what it was measured from.

Attributes:

Name Type Description
psf (Tensor, optional)

(*group, *K) PSF, spatial axes in layout order, centred at index K // 2 and normalised to unit sum.

fwhm (Tensor, optional)

(*group, D) full width at half maximum along each spatial axis, in voxels.

count (Tensor, optional)

(*group,) number of beads averaged.

centers (Tensor, optional)

(N, ndim) sub-voxel positions of the averaged beads in the data, one coordinate per storage axis (group and sample axes hold integer indices).

TileIntensityEstimate dataclass

TileIntensityEstimate(scale=None, shift=None, *, meta=dict())

Bases: Estimate

Per-tile linear intensity transform of a tiled acquisition.

Tile i (with group index g) is harmonised as

x̂ᵢ = aᵢ yᵢ + cᵢ,

with aᵢ = scale[..., i] and cᵢ = shift[..., i]. The identity transform is scale = 1, shift = 0.

Attributes:

Name Type Description
scale (Tensor, optional)

(*group, T) multiplicative factor aᵢ of each of the T tiles (dimensionless).

shift (Tensor, optional)

(*group, T) additive term cᵢ, in the units of the data (ADU).

correct

correct(y, tile)

Harmonise tile tile: aᵢ yᵢ + cᵢ.

Parameters:

Name Type Description Default
y Tensor

(*group, *spatial) tile, the group axes leading (or no group axes when the estimate has none).

required
tile int

Index of the tile.

required

Returns:

Type Description
Tensor

Fields that are None are absent terms (a = 1, c = 0).

PupilEstimate dataclass

PupilEstimate(pupil=None, zernike_magnitude=None, zernike_phase=None, *, meta=dict())

Bases: Estimate

Scalar pupil function of a microscope, and its Zernike expansion.

The pupil is sampled on the discrete Fourier grid of the lateral image grid it was estimated from: k = (i − K // 2) / (K · Δ) along each axis, so that k = 0 is at index K // 2. meta records the optics (wavelength, numerical_aperture, refractive_index) and the voxel size spacing (Δz, Δy, Δx) they refer to.

Attributes:

Name Type Description
pupil (Tensor, optional)

(*group, Ky, Kx) complex pupil function, 0 outside |k| ≤ NA/λ.

zernike_magnitude (Tensor, optional)

(*group, J) Zernike coefficients of the magnitude, Noll indices 1 … J (meta["zernike"] == "noll").

zernike_phase (Tensor, optional)

(*group, J) Zernike coefficients of the phase, in radians.