Skip to content

Attenuation (optix.attenuation)

Estimators

Attenuation along the light-sheet propagation axis.

Building blocks (tail sums, the per-method kernels and the weighted TV solver) are in optix.attenuation.utils.

DepthResolved

DepthResolved(*, axis=None, pixel_size=None, passes=None, method=None, background=None, max_gain=None, tv_axis=None, eta=None, epsilon=None, noise_power=None, faithful=True, dtype=None, device=None, layout=None)

Bases: Estimator

Depth-resolved attenuation along the light-sheet propagation axis.

The per-pixel attenuation coefficient of Vermeer et al. (2014), applied to the fluorescence profiles along the illumination propagation axis, and the compensation that follows from it; see depth_resolved for the model, its adaptation to fluorescence and the extensions, and compensate for the compensation.

There are no global parameters to fit: fit only records the layout. apply writes the compensated data and attenuation the μ map. Both stream the data in blocks that hold whole profiles (the full extent of the propagation axis, and of tv_axis with method="smith") and are tiled over the other axes, so arrays larger than memory (zarr, memmap) can be processed in one pass.

References

  1. Vermeer KA, Mo J, Weda JJA, Lemij HG, de Boer JF. Depth-resolved model-based reconstruction of attenuation coefficients in optical coherence tomography. Biomed Opt Express 5(1):322–337, 2014. doi:10.1364/BOE.5.000322
  2. Smith GT, Dwork N, O'Connor D, Sikora U, Lurie KL, Pauly JM, Ellerbee AK. Automated, depth-resolved estimation of the attenuation coefficient from optical coherence tomography data. IEEE Trans Med Imaging 34(12):2592–2602, 2015. doi:10.1109/TMI.2015.2450197
  3. Frantz D, Wright CJ, Schaser AJ, Kirik D, Kristensson E, Berrocal E. Image post-processing for SILMAS: structured illumination light sheet microscopy with axial sweeping. Biomed Opt Express 15(8):4943–4962, 2024. doi:10.1364/BOE.531210
BibTeX
@article{vermeer2014depth,
  author  = {Vermeer, Koenraad A. and Mo, Jelena and Weda,
             Jelmer J. A. and Lemij, Hans G. and
             de Boer, Johannes F.},
  title   = {Depth-resolved model-based reconstruction of
             attenuation coefficients in optical coherence
             tomography},
  journal = {Biomedical Optics Express},
  volume  = {5}, number = {1}, pages = {322--337},
  year    = {2014}, doi = {10.1364/BOE.5.000322}
}
@article{smith2015automated,
  author  = {Smith, Gennifer T. and Dwork, Nicholas and
             O'Connor, Daniel and Sikora, Uzair and
             Lurie, Kristen L. and Pauly, John M. and
             Ellerbee, Audrey K.},
  title   = {Automated, depth-resolved estimation of the
             attenuation coefficient from optical coherence
             tomography data},
  journal = {IEEE Transactions on Medical Imaging},
  volume  = {34}, number = {12}, pages = {2592--2602},
  year    = {2015}, doi = {10.1109/TMI.2015.2450197}
}
@article{frantz2024image,
  author  = {Frantz, David and Wright, Courtney J. and
             Schaser, Allison J. and Kirik, Deniz and
             Kristensson, Elias and Berrocal, Edouard},
  title   = {Image post-processing for {SILMAS}: structured
             illumination light sheet microscopy with axial
             sweeping},
  journal = {Biomedical Optics Express},
  volume  = {15}, number = {8}, pages = {4943--4962},
  year    = {2024}, doi = {10.1364/BOE.531210}
}

Configure the estimator.

Parameters:

Name Type Description Default
axis int or str

Propagation axis: a storage position of the data, or an axis label of the layout (e.g. "x").

-1
pixel_size float

Pixel size Δ along axis, in the length unit of μ⁻¹.

1.0
passes (1, 2)

p of Eq. (17) (s on the docs page): 2 in the paper, 1 for single-pass illumination (the recommended value, faithful=False); see depth_resolved.

1
method (vermeer, smith)

"smith" selects the extension of Smith et al. (2015).

"vermeer"
background (float, Tensor, SensorEstimate or ShadingEstimate)

Additive term subtracted first (extension). The offset / dark map of an estimate is (*group, *spatial) in the layout; a plain tensor broadcasts against the data in storage order.

None
max_gain float

Cap ≥ 1 of the compensation gain (extension).

None
tv_axis int or str

method="smith": lateral axis of the TV term (storage position or label). Default: the other spatial axis when the layout has two spatial axes, one of which is axis.

None
eta float | None

method="smith" options; see depth_resolved.

None
epsilon float | None

method="smith" options; see depth_resolved.

None
noise_power float | None

method="smith" options; see depth_resolved.

None
faithful bool

See Estimator.

True
dtype bool

See Estimator.

True
device bool

See Estimator.

True
layout bool

See Estimator.

True

fit

fit(data=None, *, layout=None, **kwargs)

No-op: there are no global parameters to estimate.

Parameters:

Name Type Description Default
data array - like

Unused (its layout, if labelled, is recorded).

None
layout Layout

Recorded for apply.

None
**kwargs object

Ignored (init, callback, verbose).

{}

Returns:

Type Description
DepthResolved

self

attenuation

attenuation(data, out=None)

Per-pixel attenuation coefficient μ of the data.

Parameters:

Name Type Description Default
data array - like or Labeled

Data, in the layout of the fit (unless labelled otherwise).

required
out writable array-like

Output of the shape of data (default: a new tensor).

None

Returns:

Type Description
writable array-like

μ in units of 1/pixel_size, written to out.

Transforms

Attenuation along the light-sheet propagation axis.

Building blocks (tail sums, the per-method kernels and the weighted TV solver) are in optix.attenuation.utils.

depth_resolved

depth_resolved(data, *, axis=-1, pixel_size=1.0, passes=2, method='vermeer', background=None, tv_axis=None, eta=6.0, epsilon=0.001, noise_power=0.0)

Per-pixel attenuation coefficient along the propagation axis.

The depth-resolved estimator of Vermeer et al. (2014): every pixel of a profile I[i] along the propagation axis gets

μ[i] = 1/(p·Δ) · log(1 + I[i] / ∑_{k > i} I[k]),            (17)

the ratio of the local intensity to the sum of all deeper intensities, with Δ the pixel size and p = 2 (the light crosses the tissue twice in OCT, Eq. (8); p is written s on the docs page). It follows from the single-scattering model I(z) = α·β·L₀·μ(z)·exp(−2∫₀^z μ(u) du) (Eq. (8)) and the assumption that almost all the light is attenuated within the profile, which truncates ∫_z^∞ to the end of the profile (Eq. (13)).

End of the profile: the sum runs to the last pixel, where it is empty, so μ = ∞ at the last pixel (log(1 + I/0)), and μ is overestimated towards the end of the profile when light remains there (Vermeer et al., Section 3.1, Fig. 1). Where both I[i] and the deeper sum are zero, μ is undefined and returned as NaN.

Application to fluorescence

The estimator comes from OCT, where the signal is backscatter. It is applied here to fluorescence along the illumination propagation axis of a light sheet. The OCT model assumes that a fixed fraction α of the attenuated light is backscattered; the fluorescence analogue is a locally constant fluorophore emission: the detected fluorescence is a fixed fraction of the excitation light attenuated at each depth, so I ∝ μ·L. The excitation crosses the tissue once, which corresponds to passes=1; with the default passes=2 (the paper's Eq. (17)), μ is half the single-pass coefficient. The compensated intensity (compensate) does not depend on passes, with either method. Attenuation of the emitted light on its way to the detector is not modelled.

Extensions (off by default):

  • background: an additive term (number, tensor, or the offset of a SensorEstimate or the dark of a ShadingEstimate) is subtracted first, since the model has no background (Vermeer et al. subtract the noise floor, Eq. (19)).
  • method="smith": the estimate of Smith et al. (2015), Eqs. (8)–(10),

    Î[m] = I[m] · I[m]² / (I[m]² + |c|²), μ̂[m] = Î[m] / (p·Δ·∑_{r ≥ m} Î[r]),

with the confocal and sensitivity fall-off functions of Eq. (9) set to 1 and |c|² = noise_power, followed by the intensity weighted horizontal TV denoising (iwhTV) of Eqs. (11)–(15): for every depth m, the line μ̂_m across the lateral axis tv_axis is replaced by the solution of

  minimise ½‖μ̃ − μ̂_m‖² + λ ∑_n W[n]·|μ̃[n + 1] − μ̃[n]|
  subject to μ̃ ≥ 0,   W[n] = 1/(I[m, n] + ε),
  λ = (2/p)·η/(N·Δ),

with N the number of lateral positions. For p = 2, λ = η/(N·Δ) as in the paper; the factor 2/p keeps η on the scale of the round-trip μ, so that μ̃ scales as 1/p like μ̂ and the compensated intensity does not depend on p. No tissue mask is used (X = identity in Eq. (15), N_x = N). The weight W[n] goes with the difference μ̃[n + 1] − μ̃[n] (the paper indexes the weights by pixel and the differences by pair). Negative intensities count as 0 in W. The TV strength λ·W scales as 1/intensity, so η = 6 and ε = 0.001 are tied to the intensity units of Smith et al.: scaling the data by c divides the regularisation by about c. The problem is solved exactly by a direct algorithm (see weighted_tv); Smith et al. use CVX. eta=0 skips the denoising. Where the tail sum of Î is ≤ 0, μ̂ = 0 and the compensation gain is 0.

References

  1. Vermeer KA, Mo J, Weda JJA, Lemij HG, de Boer JF. Depth-resolved model-based reconstruction of attenuation coefficients in optical coherence tomography. Biomed Opt Express 5(1):322–337, 2014. doi:10.1364/BOE.5.000322
  2. Smith GT, Dwork N, O'Connor D, Sikora U, Lurie KL, Pauly JM, Ellerbee AK. Automated, depth-resolved estimation of the attenuation coefficient from optical coherence tomography data. IEEE Trans Med Imaging 34(12):2592–2602, 2015. doi:10.1109/TMI.2015.2450197
  3. Frantz D, Wright CJ, Schaser AJ, Kirik D, Kristensson E, Berrocal E. Image post-processing for SILMAS: structured illumination light sheet microscopy with axial sweeping. Biomed Opt Express 15(8):4943–4962, 2024. doi:10.1364/BOE.531210 (attenuation compensation along the light-sheet propagation axis)
BibTeX
@article{vermeer2014depth,
  author  = {Vermeer, Koenraad A. and Mo, Jelena and Weda,
             Jelmer J. A. and Lemij, Hans G. and
             de Boer, Johannes F.},
  title   = {Depth-resolved model-based reconstruction of
             attenuation coefficients in optical coherence
             tomography},
  journal = {Biomedical Optics Express},
  volume  = {5}, number = {1}, pages = {322--337},
  year    = {2014}, doi = {10.1364/BOE.5.000322}
}
@article{smith2015automated,
  author  = {Smith, Gennifer T. and Dwork, Nicholas and
             O'Connor, Daniel and Sikora, Uzair and
             Lurie, Kristen L. and Pauly, John M. and
             Ellerbee, Audrey K.},
  title   = {Automated, depth-resolved estimation of the
             attenuation coefficient from optical coherence
             tomography data},
  journal = {IEEE Transactions on Medical Imaging},
  volume  = {34}, number = {12}, pages = {2592--2602},
  year    = {2015}, doi = {10.1109/TMI.2015.2450197}
}
@article{frantz2024image,
  author  = {Frantz, David and Wright, Courtney J. and
             Schaser, Allison J. and Kirik, Deniz and
             Kristensson, Elias and Berrocal, Edouard},
  title   = {Image post-processing for {SILMAS}: structured
             illumination light sheet microscopy with axial
             sweeping},
  journal = {Biomedical Optics Express},
  volume  = {15}, number = {8}, pages = {4943--4962},
  year    = {2024}, doi = {10.1364/BOE.531210}
}

Parameters:

Name Type Description Default
data Tensor

Intensities, any shape; non-integer dtypes are kept, integers are converted to the configured dtype.

required
axis int

Propagation axis (depth z, pixel index i increasing with depth).

-1
pixel_size float

Δ, in the length unit of μ⁻¹ (e.g. mm for μ in mm⁻¹).

1.0
passes (1, 2)

p (s on the docs page): 2 in the papers (OCT round trip); 1 for single-pass illumination (see the note above).

1
method (vermeer, smith)

Estimator: Vermeer et al. (2014), Eq. (17), or the extension of Smith et al. (2015), Eqs. (8)–(15).

"vermeer"
background (float, Tensor, SensorEstimate or ShadingEstimate)

Additive term subtracted first (extension). A tensor or an estimate's map broadcasts against data.

None
tv_axis int

method="smith": lateral axis of the TV term (the B-scan rows of the paper). Default: the other of the last two dims when axis is one of them.

None
eta float

method="smith": η ≥ 0 of Eq. (11) (6 in Smith et al., Section II-E). It refers to the round-trip (p = 2) scale of μ: the TV weight is λ = (2/p)·η/(N·Δ). The TV strength λ·W, with W = 1/(I + ε), scales as 1/intensity, so η (like ε) is meaningful in the intensity units of Smith et al.

6.0
epsilon float

method="smith": ε of Eq. (14) (0.001 in Smith et al., chosen for the magnitude of their intensities).

1e-3
noise_power float

method="smith": |c|² of Eq. (9) (user-specified in the paper); 0 disables the restoration filter.

0.0

Returns:

Type Description
Tensor

μ, of the shape of data, in units of 1/pixel_size.

compensate

compensate(data, *, axis=-1, pixel_size=1.0, passes=2, method='vermeer', background=None, max_gain=None, tv_axis=None, eta=6.0, epsilon=0.001, noise_power=0.0)

Compensate the attenuation along the propagation axis.

Under the model of depth_resolved, I[i] ∝ μ[i]·exp(−p·∫₀^{z_i} μ), the attenuation up to pixel i is undone by

I_c[i] = I[i] · exp(p·Δ·∑_{j < i} μ[j]).

Vermeer et al. (2014) and Smith et al. (2015) estimate μ but give no compensated intensity; this formula is derived from their model and is not part of the papers. With Vermeer's μ (Eq. (17)), exp(p·Δ·μ[j]) = T[j]/T[j + 1] with T[i] = ∑_{k ≥ i} I[k], and the product telescopes to the exact closed form

I_c[i] = I[i] · T[0] / T[i],

which is what is computed (it depends neither on p nor on Δ). Where T[i] ≤ 0 (no signal from pixel i on) or T[0] ≤ 0, I_c[i] = 0. With method="smith", the cumulated sum of the denoised μ̃ is used, with the same zeroing on the tail sums of Î; it does not depend on p nor on Δ either (see eta in depth_resolved). The exponential is capped so that the output stays finite. The compensated intensity is proportional to μ·L₀ (for fluorescence: the local emission under the uniform-emission assumption), so a uniform medium gives a flat profile. See depth_resolved for the model, its adaptation to fluorescence, the options and the references.

Extension: max_gain caps the gain T[0]/T[i] (or the exponential) to limit the amplification of the noise deep in the profile.

Parameters:

Name Type Description Default
data Tensor

Intensities.

required
axis int -1
pixel_size int -1
passes int -1
method int -1
background int -1
max_gain float

Upper bound ≥ 1 of the gain (extension; default: none).

None
tv_axis int | None

method="smith" options; see depth_resolved.

None
eta int | None

method="smith" options; see depth_resolved.

None
epsilon int | None

method="smith" options; see depth_resolved.

None
noise_power int | None

method="smith" options; see depth_resolved.

None

Returns:

Type Description
Tensor

I_c, of the shape and dtype of data (after background subtraction).

Utilities

No stability promise

optix.attenuation.utils holds building blocks of the estimators above; they may change without notice.

Building blocks of the attenuation estimators.

Semi-public: these may change without notice.

tail_sums

tail_sums(data, dim=-1, *, inclusive=True)

Sums of the deeper intensities along dim, in float64.

T[i] = ∑_{k ≥ i} I[k]   (inclusive),   ∑_{k > i} I[k]   (exclusive).

Accumulated in float64 (float32 on MPS) whatever the input dtype, so that the long sums of the deep, small intensities keep their precision.

Parameters:

Name Type Description Default
data Tensor

Intensities I.

required
dim int

Propagation axis.

-1
inclusive bool

Whether T[i] includes I[i].

True

Returns:

Type Description
Tensor

Shape of data, float64 (float32 on MPS).

vermeer_attenuation

vermeer_attenuation(data, dim=-1, *, pixel_size=1.0, passes=2)

Per-pixel attenuation coefficient of Vermeer et al. (2014), Eq. (17).

μ[i] = 1/(p·Δ) · log(1 + I[i] / ∑_{k > i} I[k]),

with p = 2 passes in the paper (Eq. (8)) and Δ the pixel size. The sum runs to the last pixel of the profile (the limited depth range of Eq. (13)). For the last pixel the sum is empty and μ = ∞; where both I[i] and the sum vanish, μ is undefined and returned as NaN.

Parameters:

Name Type Description Default
data Tensor

Intensities I ≥ 0 along dim.

required
dim int

Propagation axis.

-1
pixel_size float

Δ, in the length unit of μ⁻¹.

1.0
passes (1, 2)

p.

1

Returns:

Type Description
Tensor

μ, of the shape and dtype of data.

vermeer_gain

vermeer_gain(data, dim=-1)

Compensation gain exp(p·Δ·∑_{j < i} μ[j]) for Vermeer's μ.

Eq. (17) gives exp(p·Δ·μ[j]) = T[j] / T[j + 1], with the inclusive tail sums T[i] = ∑_{k ≥ i} I[k], so the product telescopes to

G[i] = T[0] / T[i],

which is computed directly (no exponential, no cumulated logarithm). G does not depend on p nor on Δ. Where T[i] ≤ 0 (no signal from i on) or T[0] ≤ 0 (no signal in the profile, e.g. after a background subtraction), G = 0.

Parameters:

Name Type Description Default
data Tensor

Intensities I along dim.

required
dim int

Propagation axis.

-1

Returns:

Type Description
Tensor

G, in the accumulation dtype of tail_sums.

compensation_gain

compensation_gain(mu, dim=-1, *, pixel_size=1.0, passes=2)

Compensation gain G[i] = exp(p·Δ·∑_{j < i} μ[j]) from a μ profile.

The attenuation of the model, I[i] ∝ μ[i]·exp(−p·∫₀^{z_i} μ), up to the front of pixel i. The cumulative sum is taken in float64 (float32 on MPS), and the exponent is capped at log of the largest finite value of that dtype, so that G stays finite.

Parameters:

Name Type Description Default
mu Tensor

Finite attenuation coefficients along dim.

required
dim int
-1
pixel_size float
1.0
passes (1, 2)
1

Returns:

Type Description
Tensor

G, in the accumulation dtype.

smith_attenuation

smith_attenuation(data, dim=-1, *, pixel_size=1.0, passes=2, noise_power=0.0)

Attenuation estimate of Smith et al. (2015), Eqs. (8)–(10).

Î[m] = I[m] · I[m]² / (I[m]² + |c|²),                 (8)–(9)
μ̂[m] = Î[m] / (p·Δ·∑_{r ≥ m} Î[r]),                   (10)

with the confocal and fall-off functions of Eq. (9) set to 1, and |c|² the noise power. The sum includes pixel m, so the last pixel gets μ̂ = 1/(p·Δ). Where the sum is ≤ 0 (no signal from m on, or noise of negative sum after a background subtraction), μ̂ = 0.

Parameters:

Name Type Description Default
data Tensor

Intensities along dim.

required
dim int
-1
pixel_size float

Δz.

1.0
passes (1, 2)

p (2 in the paper).

1
noise_power float

|c|² ≥ 0 of Eq. (9); 0 disables the restoration filter.

0.0

Returns:

Type Description
Tensor

μ̂, of the shape and dtype of data.

weighted_tv

weighted_tv(data, weights, lam, dim=-1, *, nonneg=True)

Weighted 1-D total-variation denoising along dim.

Solves exactly, independently for every line along dim,

minimise ½‖x − y‖² + λ ∑_n w[n]·|x[n + 1] − x[n]|   s.t. x ≥ 0,

the problem (11) of Smith et al. (2015) with the weighted TV of Eqs. (13)–(15). The weights w hold N − 1 values along dim (or N, the last one being ignored). The unconstrained problem is solved by the direct dynamic-programming algorithm of Johnson (2013), which handles a weight per difference, in O(N) per line and vectorised across lines; the constraint is then imposed by clamping, since in 1-D prox(TV + ι_{x ≥ 0})(y) = max(prox_TV(y), 0). Smith et al. use CVX. Computed in float64 (float32 on MPS).

References

  1. Johnson NA. A dynamic programming algorithm for the fused lasso and L0-segmentation. J Comput Graph Stat 22(2):246–260, 2013. doi:10.1080/10618600.2012.681238
BibTeX
@article{johnson2013dynamic,
  author  = {Johnson, Nicholas A.},
  title   = {A dynamic programming algorithm for the fused
             lasso and {L0}-segmentation},
  journal = {Journal of Computational and Graphical Statistics},
  volume  = {22}, number = {2}, pages = {246--260},
  year    = {2013}, doi = {10.1080/10618600.2012.681238}
}

Parameters:

Name Type Description Default
data Tensor

y.

required
weights Tensor

w ≥ 0, broadcastable to data (N or N − 1 along dim).

required
lam float

λ ≥ 0.

required
dim int
-1
nonneg bool

Impose x ≥ 0.

True

Returns:

Type Description
Tensor

x, of the shape and dtype of data.