Deconvolution (optix.deconv)
Deconvolution with a known point spread function.
Estimators
Deconvolution with a known point spread function.
Richardson–Lucy for Poisson counts, its acceleration by Biggs & Andrews (1997), its extension by Snyder et al. (1993) to CCD data (flat field, background counts, read noise) and its total-variation regularisation by Dey et al. (2006); multiview deconvolution of registered views by Preibisch et al. (2014); the linear Wiener and Tikhonov filters; the regularised shifted-Poisson deconvolution of Ikoma et al. (2018) and the Hessian Schatten-norm Poisson deconvolution of Lefkimmiatis & Unser (2013), both solved by ADMM, and the exact Poisson–Gaussian likelihood deconvolution of Chouzenoux et al. (2015), solved by primal–dual splitting. Spatially variant blur: the PSF models of Nagy & O'Leary (1998) and Denis et al. (2015), usable as the PSF of the Richardson–Lucy family, and the preconditioned conjugate-gradient restoration of Nagy & O'Leary.
Building blocks (FFT convolution with padding, the shift-variant
operator, the Richardson–Lucy update, the Biggs–Andrews acceleration
parameter, the back projectors) are in optix.deconv.utils.
RichardsonLucy
RichardsonLucy(psf=None, *, n_iter=None, alpha=None, max_iter=None, damping=None, halo=None, block=None, faithful=True, dtype=None, device=None, layout=None)
Bases: _BlockDeconvolution
Richardson–Lucy deconvolution with a known PSF, block by block.
Model: the image y is a Poisson sample of the blurred object,
y ~ Poisson(H f), (H f)ᵢ = ∑ⱼ S(i − j) fⱼ,
with S the point spread function (normalised to unit sum). The iteration of Richardson (1972) and Lucy (1974) is
f⁽ʳ⁺¹⁾ = f⁽ʳ⁾ · Hᵀ[y / (H f⁽ʳ⁾)] / Hᵀ1.
It keeps f ≥ 0, increases the Poisson likelihood of y at every step, and conserves the flux: ∑ᵢ (H f⁽ʳ⁾)ᵢ = ∑ᵢ yᵢ for r ≥ 1.
Starting estimate. The uniform image of the same integrated intensity as the data (Richardson's f⁽⁰⁾ = W/I; Lucy: a smooth, non-negative image with the data's integrated intensity), one level per image.
Stopping rule. Lucy (1974, §IV): stop
as soon as the χ² test of the fit, P(χ² > χ²_obs) with χ²_obs = ∑ᵢ (yᵢ −
μᵢ)²/μᵢ, μ = H f⁽ʳ⁾, and ν = |Ω| − 1 degrees of freedom, is not small (≥
alpha = 0.05). The test assumes y in counts (photons or electrons). A
fixed number of iterations
(Richardson shows 10, 20 and 30)
is selected with n_iter.
Boundaries and blocks. The object is estimated on a domain that extends past the observed region by the PSF support, so light from outside the field of view is modelled rather than piled up at the edges. H crops the blurred object to the observed region and the normaliser Hᵀ1, which falls below 1 near the edges of that region, is computed on the padded grid. Large inputs are processed in blocks with a halo; each block is deconvolved as an image of its own (core plus halo), and only its core is kept. The halo is at least the PSF size (default: twice), and the seams fade with the halo width; along an image edge, the block-wise and whole-image results coincide.
Shift-variant PSF. Lucy (1974) states the iteration for any
kernel P(x|ξ), not only a convolution: with a shift-variant PSF model
as psf, H is the model's blur (a sum of weighted convolutions, see
ShiftVariantPSF), Hᵀ its
exact transpose and Hᵀ1 its normaliser. The weights of each block are
evaluated at the global position of its pixels.
Images are independent: sample and group axes of the layout are iterated over, the spatial axes (as many as the PSF has dims, in layout order) are deconvolved.
Snyder et al. (1993) extend the model to CCD data (flat field,
background counts, read noise): see
Snyder.
Extensions (off by default)
- Camera model:
fit(data, init=sensor)with aSensorEstimateconverts the data to electrons, (y − offset)/gain, before deconvolution; the result is then in electrons. - Damping:
damping=εapplies a fraction ε ∈ (0, 1] of the correction, f ← f + ε(f·c − f), as in Lucy (1974, §III), where it is used to prove that the likelihood increases; Lucy recommends ε = 1.
References
- Richardson WH. Bayesian-based iterative method of image restoration. J Opt Soc Am 62(1):55-59, 1972. doi:10.1364/JOSA.62.000055
- Lucy LB. An iterative technique for the rectification of observed distributions. Astron J 79(6):745-754, 1974. doi:10.1086/111605
BibTeX
@article{richardson1972bayesian,
author = {Richardson, William Hadley},
title = {Bayesian-Based Iterative Method of Image
Restoration},
journal = {Journal of the Optical Society of America},
volume = {62},
number = {1},
pages = {55--59},
year = {1972},
doi = {10.1364/JOSA.62.000055}
}
@article{lucy1974iterative,
author = {Lucy, L. B.},
title = {An iterative technique for the rectification of
observed distributions},
journal = {The Astronomical Journal},
volume = {79},
number = {6},
pages = {745--754},
year = {1974},
doi = {10.1086/111605}
}
Examples:
>>> import torch
>>> from optix.deconv import RichardsonLucy
>>> psf = torch.ones(5, 5)
>>> data = torch.poisson(torch.full((64, 64), 10.0))
>>> rl = RichardsonLucy(psf, n_iter=10).fit(data)
>>> rl.apply(data).shape
torch.Size([64, 64])
Configure the deconvolution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
psf
|
Tensor or ShiftVariantPSF
|
Point spread function, |
None
|
n_iter
|
int
|
Fixed number of iterations. Default (Lucy 1974): None, the χ² stopping rule. |
None
|
alpha
|
float
|
Level of the χ² stopping test: stop once P(χ² > χ²_obs) ≥ |
None
|
max_iter
|
int
|
Iteration cap of the χ² stopping rule. Default: 100 (not specified in the papers). |
None
|
damping
|
float
|
Extension. Fraction ε ∈ (0, 1] of the correction applied. Default (Lucy 1974): 1. |
None
|
halo
|
int or sequence of int
|
Halo width per spatial axis, at least the PSF size along that axis. Default: twice the PSF size (not specified in the papers). |
None
|
block
|
sequence of int or None
|
Core block size per spatial axis (None entries: whole extent). Default: chosen from the memory budget. |
None
|
faithful
|
bool
|
See |
True
|
dtype
|
bool
|
See |
True
|
device
|
bool
|
See |
True
|
layout
|
bool
|
See |
True
|
RichardsonLucyTV
RichardsonLucyTV(psf=None, *, lambda_tv=None, n_iter=None, tol=None, max_iter=None, epsilon=None, start=None, halo=None, block=None, faithful=True, dtype=None, device=None, layout=None)
Bases: RichardsonLucy
Richardson–Lucy deconvolution with total-variation regularisation.
Model (Dey et al. 2006): the image i is a Poisson sample of the blurred object, i ~ Poisson(o ∗ h), and the object minimises the negative log-likelihood plus its total variation,
J(o) = ∑ₛ [(o ∗ h)(s) − i(s) log (o ∗ h)(s)] + λ_TV ∑ₛ |∇o(s)|.
The minimisation uses the explicit, one-step-late multiplicative scheme of Green (1990), Eq. 11 of the paper:
oₖ₊₁ = oₖ · [(i / (oₖ ∗ h)) ⋆ h] / (1 − λ_TV div(∇oₖ / |∇oₖ|)),
i.e. the Richardson–Lucy correction of
RichardsonLucy divided by the
derivative of the regulariser. TV smooths along the level lines of
the image and not across them, so edges are kept while the noise
amplification of plain Richardson–Lucy is suppressed. With
λ_TV = 0 the iteration is plain Richardson–Lucy.
Regularisation weight. λ_TV = 0.002, the value used by the paper for all synthetic data (0.005 for one real data set).
Discretisation of the TV term. Not specified in the paper:
forward differences for ∇, backward differences for div, unit voxel
spacing along every axis (λ_TV acts per voxel, also along an
anisotropic axis; the paper's data are anisotropic and it does not
say whether it weighted the axial differences), and the unit normal
∇o/|∇o| set to 0 where the gradient is at the round-off level (see
tv_curvature). The paper gives
no ε for |∇o|; one can be set with epsilon.
Positivity. The paper requires 1 − λ_TV div(∇o/|∇o|) > 0 and obtains it by keeping λ_TV small. With this discretisation |div(∇o/|∇o|)| ≤ d + √d in d dims, so λ_TV < 1 / (d + √d) (0.29 in 2-D, 0.21 in 3-D) guarantees a positive denominator; larger values are refused.
Starting estimate. The measured image (negative values set to 0),
as in the paper; its scale does not matter, since both the
Richardson–Lucy correction and the TV term are invariant to the
scale of o. Pixels at 0 in the start stay at 0 (multiplicative
update): with start="data", every zero-count voxel stays at 0 for
the whole run, as in the paper; start="uniform" avoids this for
sparse, photon-limited data. Outside the observed region (see
Boundaries), the start is the mean of the image.
Stopping rule. The paper stops "at convergence, defined when the
relative difference between two images is less than a threshold"
of 10⁻⁵. The relative difference is ‖oₖ₊₁ − oₖ‖₂ / ‖oₖ‖₂ on the
observed block (the norm is not specified in the paper), and the
iteration is capped at max_iter = 1000 (not specified in the
paper). With the default ε the threshold is usually not reached: the
one-step-late TV iteration keeps oscillating in flat noisy regions,
where the normals ∇o/|∇o| keep changing direction, and the relative
change plateaus near 1.5 · 10⁻³, so max_iter is the effective
stop. A fixed number of iterations is selected with n_iter; a
larger epsilon (extension) smooths the TV term and gives a stop
that does trigger.
Boundaries and blocks. As in
RichardsonLucy: the object is
estimated on a domain extended by the PSF support, and the
normalised correction (Hᵀ1 ≠ 1 near the edges) is divided by the TV
denominator; Eq. 11 is written for Hᵀ1 = 1. The TV stencil reaches
one voxel beyond the PSF, so the halo of each block is at least the
PSF size plus one (default: twice that). The stopping rule is
applied per block.
Extensions (off by default)
- Camera model:
fit(data, init=sensor)with aSensorEstimateconverts the data to electrons, as inRichardsonLucy. - Uniform start:
start="uniform"starts from the uniform image ofRichardsonLucyinstead of the measured image.
References
- Dey N, Blanc-Féraud L, Zimmer C, Roux P, Kam Z, Olivo-Marin JC, Zerubia J. Richardson–Lucy algorithm with total variation regularization for 3D confocal microscope deconvolution. Microsc Res Tech 69(4):260-266, 2006. doi:10.1002/jemt.20294
- Green PJ. On use of the EM algorithm for penalized likelihood estimation. J R Stat Soc B 52(3):443-452, 1990. doi:10.1111/j.2517-6161.1990.tb01798.x
BibTeX
@article{dey2006richardson,
author = {Dey, Nicolas and Blanc-Féraud, Laure and
Zimmer, Christophe and Roux, Pascal and
Kam, Zvi and Olivo-Marin, Jean-Christophe and
Zerubia, Josiane},
title = {Richardson--Lucy algorithm with total variation
regularization for {3D} confocal microscope
deconvolution},
journal = {Microscopy Research and Technique},
volume = {69},
number = {4},
pages = {260--266},
year = {2006},
doi = {10.1002/jemt.20294}
}
@article{green1990use,
author = {Green, Peter J.},
title = {On use of the {EM} algorithm for penalized
likelihood estimation},
journal = {Journal of the Royal Statistical Society:
Series B (Methodological)},
volume = {52},
number = {3},
pages = {443--452},
year = {1990},
doi = {10.1111/j.2517-6161.1990.tb01798.x}
}
Examples:
>>> import torch
>>> from optix.deconv import RichardsonLucyTV
>>> psf = torch.ones(5, 5)
>>> data = torch.poisson(torch.full((64, 64), 10.0))
>>> est = RichardsonLucyTV(psf, n_iter=10).fit(data)
>>> est.apply(data).shape
torch.Size([64, 64])
Configure the deconvolution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
psf
|
Tensor
|
Point spread function, |
None
|
lambda_tv
|
float
|
Weight λ_TV of the total variation, 0 ≤ λ_TV < 1 / (d + √d). Default (Dey et al. 2006): 0.002. |
None
|
n_iter
|
int
|
Fixed number of iterations. Default: None, the relative-change stopping rule. |
None
|
tol
|
float
|
Threshold of the relative change between two iterates. Default (Dey et al. 2006): 10⁻⁵. |
None
|
max_iter
|
int
|
Iteration cap of the stopping rule. Default: 1000 (not specified in the paper). |
None
|
epsilon
|
float
|
Floor ε of |∇f| in the TV term. Default: None, the round-off level of the working dtype times max|f|, only to avoid 0/0 (not specified in the paper). |
None
|
start
|
(data, uniform)
|
Starting estimate: the measured image, or (extension) the
uniform image of the same integrated intensity. Default (Dey
et al. 2006): |
"data"
|
halo
|
int or sequence of int
|
Halo width per spatial axis, at least the PSF size plus one along that axis. Default: twice the PSF size plus one (not specified in the paper). |
None
|
block
|
sequence of int or None
|
Core block size per spatial axis (None entries: whole extent). Default: chosen from the memory budget. |
None
|
faithful
|
bool
|
See |
True
|
dtype
|
bool
|
See |
True
|
device
|
bool
|
See |
True
|
layout
|
bool
|
See |
True
|
Snyder
Snyder(psf=None, *, noise=None, flat=None, background=None, sieve=None, n_iter=None, alpha=None, max_iter=None, halo=None, block=None, faithful=True, dtype=None, device=None, layout=None)
Bases: RichardsonLucy
Deconvolution of CCD camera data (Snyder, Hammoud & White 1993).
Data model (Eqs. 5–11). The value read from pixel j, in electrons, is
r(j) = n_obj(j) + n₀(j) + g(j),
- n_obj(j) ~ Poisson(β(j) ∑ᵢ p(j|i) λ(i)): photo-electrons from the object λ, blurred by the PSF p and detected with efficiency β(j), the flat field (Eqs. 6 and 11);
- n₀(j) ~ Poisson(μ₀(j)): background counts, from external and internal background radiation, dark current and the Poisson ("fat zero") part of the bias (Eqs. 7–8);
- g(j) ~ N(m, σ²): read noise of the output amplifier, whose mean m is the deterministic bias.
The estimate maximises the likelihood of r (Eq. 10) under λ ≥ 0, by expectation–maximisation. With μₖ(j) = β(j) ∑ᵢ p(j|i) λₖ(i) + μ₀(j) (Eq. 20) and β̄(i) = ∑ⱼ β(j) p(j|i), the iteration is (Eq. 18)
λₖ₊₁(i) = λₖ(i)/β̄(i) · ∑ⱼ β(j) p(j|i) F[r(j), μₖ(j), σ] / μₖ(j),
where F[r, μ, σ] = E[n_obj + n₀ | r] is the conditional mean of the Poisson counts given the data (Eqs. 19 and 21),
F[r, μ, σ] = ∑ₙ n μⁿ/n! e^{−(r−n−m)²/2σ²}
/ ∑ₙ μⁿ/n! e^{−(r−n−m)²/2σ²}
(see poisson_normal_mean).
Every iterate is non-negative and the likelihood never decreases.
Without read noise (σ → 0), F = r − m and Eq. (18) is Eq. (15) on the
bias-corrected data; with β = 1, μ₀ = 0 and σ = 0 it is the
Richardson–Lucy iteration.
Read noise. noise="exact" (the default) evaluates F at every
iteration and pixel, which holds for any read-noise level; it is the
iteration that the paper builds on (regularisation, Section 4, and
spectral response, Section 3.D). noise="shifted-poisson" is the
large-variance approximation of Section 3.C: with m = σ², g is close
in distribution to a Poisson variable of mean σ², so the data,
shifted so that m = σ², are Poisson with mean μₖ + σ², and Eq. (15)
is used with r + σ² − m in place of r and μ₀ + σ² in place of μ₀.
The paper's Hubble Space Telescope example uses this approximation.
The shifted data are clipped at 0 (not specified in the paper).
Camera calibration. The model terms are taken from the estimates
given to fit (init=sensor,
init=shading or init=[sensor, shading]) and from the options:
SensorEstimate: the data are converted to electrons, r = (y − offset)/gain.offsetis the deterministic bias m (it is subtracted, so m = 0 in electrons),variance/gain² is σ². Without a sensor estimate the data are taken in electrons with m = 0 and σ = 0.ShadingEstimate:flatis β, rescaled to unit mean (so λ is in electrons at a pixel of average efficiency);dark, which includes the camera offset, gives the dark counts (dark − offset)/gain, clipped at 0, added to μ₀ as Poisson counts, never subtracted from the data. A per-framebaselineis not part of the model and is ignored.flat=β: the flat field, used as given (for example a quantum efficiency map in (0, 1]); it takes precedence over the shading estimate's.background=b: further background counts, in data units with the offset excluded, b/gain added to μ₀.
The flat field enters the model rather than being divided out of the data, which would make them no longer Poisson (Section 1).
Regularisation (Section 4, Eq. 30). sieve=s blurs the final
iterate with the kernel s (normalised to unit sum): the method of
sieves with equal sieve and resolution kernels, which estimates the
blurred object d = s * λ. Default: none, as in the paper's example.
Starting estimate and stopping rule. Not specified in the paper.
As in RichardsonLucy, the start is
uniform, ∑ⱼ (r(j) − μ₀(j)) / ∑ⱼ β(j) per image, and the iteration
stops at Lucy's χ² test, with the variance of the data,
χ²_obs = ∑ⱼ (r(j) − m − μₖ(j))² / (μₖ(j) + σ²), or after n_iter
iterations (the paper's example uses 600). Boundaries, blocks and
layouts are handled as in
RichardsonLucy.
References
- Snyder DL, Hammoud AM, White RL. Image recovery from data acquired with a charge-coupled-device camera. J Opt Soc Am A 10(5):1014-1023, 1993. doi:10.1364/JOSAA.10.001014
- Lucy LB. An iterative technique for the rectification of observed distributions. Astron J 79(6):745-754, 1974. doi:10.1086/111605
BibTeX
@article{snyder1993image,
author = {Snyder, Donald L. and Hammoud, Abed M. and
White, Richard L.},
title = {Image recovery from data acquired with a
charge-coupled-device camera},
journal = {Journal of the Optical Society of America A},
volume = {10},
number = {5},
pages = {1014--1023},
year = {1993},
doi = {10.1364/JOSAA.10.001014}
}
@article{lucy1974iterative,
author = {Lucy, L. B.},
title = {An iterative technique for the rectification of
observed distributions},
journal = {The Astronomical Journal},
volume = {79},
number = {6},
pages = {745--754},
year = {1974},
doi = {10.1086/111605}
}
Examples:
>>> import torch
>>> from optix.deconv import Snyder
>>> from optix.estimates import SensorEstimate
>>> psf = torch.ones(5, 5)
>>> data = 100 + torch.poisson(torch.full((64, 64), 10.0))
>>> sensor = SensorEstimate(offset=100.0, gain=1.0, variance=4.0)
>>> est = Snyder(psf, n_iter=10).fit(data, init=sensor)
>>> est.apply(data).shape
torch.Size([64, 64])
Configure the deconvolution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
psf
|
Tensor or ShiftVariantPSF
|
Point spread function p, |
None
|
noise
|
(exact, shifted - poisson)
|
Read-noise treatment: the exact conditional mean F of Eq. (21) (default), or the shifted-Poisson approximation of Section 3.C. |
"exact"
|
flat
|
Tensor
|
Flat field β ≥ 0 (detection efficiency), a map that broadcasts
to |
None
|
background
|
float or Tensor
|
Background counts in data units (offset excluded), a scalar
or a map that broadcasts to |
None
|
sieve
|
Tensor
|
Sieve kernel s (Section 4), no larger than the PSF along any
axis, centred at |
None
|
n_iter
|
int
|
Fixed number of iterations. Default: None, the χ² stopping rule (not specified in the paper). |
None
|
alpha
|
float
|
Level of the χ² stopping test. Default: 0.05 (Lucy 1974). |
None
|
max_iter
|
int
|
Iteration cap of the χ² stopping rule. Default: 100 (not specified in the paper). |
None
|
halo
|
int or sequence of int
|
Halo width per spatial axis, at least the PSF size along that axis. Default: twice the PSF size (not specified in the paper). |
None
|
block
|
sequence of int or None
|
Core block size per spatial axis (None entries: whole extent). Default: chosen from the memory budget. |
None
|
faithful
|
bool
|
See |
True
|
dtype
|
bool
|
See |
True
|
device
|
bool
|
See |
True
|
layout
|
bool
|
See |
True
|
WienerButterworth
WienerButterworth(psf=None, *, back_projector=None, wiener=None, cutoff_gain=None, order=None, fwhm=None, start=None, n_iter=None, chi2_stop=None, alpha=None, max_iter=None, damping=None, halo=None, block=None, faithful=True, dtype=None, device=None, layout=None)
Bases: RichardsonLucy
Richardson–Lucy deconvolution with an unmatched back projector.
Guo et al. (2020) replace the transposed PSF of the Richardson–Lucy update by a back projector b chosen so that the product of the transfer functions, DFT(b)·DFT(f), is close to flat over the pass band of the PSF (Supplementary Note 1, after Zeng & Gullberg 2000):
e⁽ᵏ⁺¹⁾ = e⁽ᵏ⁾ · B[y / (H e⁽ᵏ⁾)] / B1,
with H the blur by the PSF f and B the convolution with b, of unit sum (B1 = 1 away from the image edges). The default b is the Wiener–Butterworth (WB) filter, a Wiener inverse of the OTF times a Butterworth low-pass filter (Supplementary Note 2, Eq. 25):
DFT(b) ∝ conj(F) / (|F|² + α) · 1 / √(1 + ε² [∑ₐ (kₐ/k_cₐ)²]ⁿ),
with F the OTF, k_c = 1/FWHM of the PSF per axis, and ε² = 1/β² − 1
(β the Butterworth gain at the cutoff; the WB gain there is β times
the Wiener gain, Eq. 27). See
back_projector for the
Gaussian and Butterworth back projectors the paper compares, and
the traditional one (b the flipped PSF: plain Richardson–Lucy).
Defaults. α = β = 0.001, n = 8 and a single iteration: the values of Supplementary Table S2.1 for the iSIM and confocal data (the paper uses α, β ∈ [0.001, 0.05], n ∈ [4, 10] and 1-5 iterations, and recommends a single iteration as a rule of thumb). The starting estimate is the measured image with its zeros replaced by 0.001 (Methods). On the margin of the object domain, outside the image, it is the mean of the image (not specified in the paper).
Cutoff frequency and the figures of the paper
The cutoff is k_c = 1/FWHM of the PSF per axis, as defined in the
text (Supplementary Note 2, §4.1). The WB filter plotted in
Supplementary Fig. S2.3 corresponds to a cutoff about 1.3 times
higher than 1/FWHM of the PSF of Fig. S2.1, and the Butterworth
filter of Fig. S2.2b is drawn with a higher order than the n = 8
of its caption. A higher cutoff passes more of the OTF and
sharpens the estimate faster per iteration; it is set by passing
a smaller fwhm (e.g. the FWHM of the PSF divided by 1.3).
Kernel support. The filtered kernels ring over many PSF widths:
b is kept on 12 widths per axis (see
kernel_shape and
back_projector), and the PSF
is zero-padded to that support, so that the padded grid of each
block and the default halo (twice the support) cover the kernel.
Convergence
With an unmatched back projector the iteration is not the expectation-maximisation algorithm: the Poisson likelihood need not increase, the flux need not be conserved, and convergence is not guaranteed (Zeng & Gullberg 2000 give conditions on b, which the paper notes the truncation below invalidates). The paper uses a few WB iterations (1-5) where Richardson–Lucy needs tens; more iterations can introduce artefacts (main text, Discussion). The WB back projector has negative lobes, so the update can produce negative values: as in the paper, they are set to 0 at each iteration, and a pixel set to 0 stays at 0.
Boundaries, blocks, layouts and the extensions (camera model,
damping) are as in
RichardsonLucy. The paper uses a
periodic (circulant) model; here the object extends past the image,
and on the margin of that domain (outside the image) the matched
update Hᵀ is used (see
BackProjection; not in the
paper).
Extensions (off by default)
- χ² stopping rule:
chi2_stop=Truestops with Lucy's χ² test (alpha,max_iter) instead of aftern_iteriterations. - Uniform start:
start="uniform"starts from the mean of the image; the first iteration is then the linear filter e⁽¹⁾ = y * b (Supplementary Note 3). - The extensions of
RichardsonLucy.
References
- Guo M, Li Y, Su Y, Lambert T, Dalle Nogare D, Moyle MW, Duncan LH, Ikegami R, Santella A, Rey-Suarez I, Green D, Beiriger A, Chen J, Vishwasrao H, Ganesan S, Prince V, Waters JC, Annunziata CM, Hafner M, Mohler WA, Chitnis AB, Upadhyaya A, Usdin TB, Bao Z, Colón-Ramos D, La Riviere P, Liu H, Wu Y, Shroff H. Rapid image deconvolution and multiview fusion for optical microscopy. Nat Biotechnol 38(11):1337-1346, 2020. doi:10.1038/s41587-020-0560-x
- Zeng GL, Gullberg GT. Unmatched projector/backprojector pairs in an iterative reconstruction algorithm. IEEE Trans Med Imaging 19(5):548-555, 2000. doi:10.1109/42.870265
BibTeX
@article{guo2020rapid,
author = {Guo, Min and Li, Yue and Su, Yijun and Lambert,
Talley and Dalle Nogare, Damian and Moyle, Mark W.
and Duncan, Leighton H. and Ikegami, Richard and
Santella, Anthony and Rey-Suarez, Ivan and Green,
Daniel and Beiriger, Anastasia and Chen, Jiji and
Vishwasrao, Harshad and Ganesan, Sundar and
Prince, Victoria and Waters, Jennifer C. and
Annunziata, Christina M. and Hafner, Markus and
Mohler, William A. and Chitnis, Ajay B. and
Upadhyaya, Arpita and Usdin, Ted B. and Bao,
Zhirong and Col{\'o}n-Ramos, Daniel and
La Riviere, Patrick and Liu, Huafeng and Wu,
Yicong and Shroff, Hari},
title = {Rapid image deconvolution and multiview fusion
for optical microscopy},
journal = {Nature Biotechnology},
volume = {38},
number = {11},
pages = {1337--1346},
year = {2020},
doi = {10.1038/s41587-020-0560-x}
}
@article{zeng2000unmatched,
author = {Zeng, Gengsheng L. and Gullberg, Grant T.},
title = {Unmatched projector/backprojector pairs in an
iterative reconstruction algorithm},
journal = {IEEE Transactions on Medical Imaging},
volume = {19},
number = {5},
pages = {548--555},
year = {2000},
doi = {10.1109/42.870265}
}
Examples:
>>> import torch
>>> from optix.deconv import WienerButterworth
>>> from optix.models import gaussian_psf
>>> psf = gaussian_psf((15, 15), sigma=2.0)
>>> data = torch.poisson(torch.full((64, 64), 10.0))
>>> wb = WienerButterworth(psf).fit(data)
>>> wb.apply(data).shape
torch.Size([64, 64])
Configure the deconvolution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
psf
|
Tensor
|
Point spread function (forward projector f), |
None
|
back_projector
|
str
|
|
None
|
wiener
|
float
|
Wiener parameter α. Default (Table S2.1, iSIM): 0.001. |
None
|
cutoff_gain
|
float
|
Butterworth gain β at the cutoff frequency. Default (Table S2.1, iSIM): 0.001. |
None
|
order
|
float
|
Butterworth order n. Default (Table S2.1, iSIM): 8. |
None
|
fwhm
|
float or sequence of float
|
Resolution per spatial axis, in pixels: the cutoff frequency
is 1/FWHM. Default: the FWHM of |
None
|
start
|
str
|
Starting estimate: |
None
|
n_iter
|
int
|
Number of iterations. Default (Table S2.1, iSIM): 1. |
None
|
chi2_stop
|
bool
|
Extension. Stop with the χ² test of
|
None
|
alpha
|
float
|
Level of the χ² stopping test (with |
None
|
max_iter
|
int
|
Iteration cap of the χ² stopping rule. Default: 100. |
None
|
damping
|
float | None
|
Extensions and blocking, as in
|
None
|
halo
|
float | None
|
Extensions and blocking, as in
|
None
|
block
|
float | None
|
Extensions and blocking, as in
|
None
|
faithful
|
bool
|
See |
True
|
dtype
|
bool
|
See |
True
|
device
|
bool
|
See |
True
|
layout
|
bool
|
See |
True
|
kernel
kernel(**backend)
The back-projector kernel b of the PSF, (*K').
See back_projector and
kernel_shape.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**backend
|
object
|
|
{}
|
Returns:
| Type | Description |
|---|---|
Tensor
|
Kernel b, of unit sum. |
BiggsAndrews
BiggsAndrews(psf=None, *, n_iter=None, alpha=None, max_iter=None, damping=None, halo=None, block=None, alpha_scope=None, faithful=True, dtype=None, device=None, layout=None)
Bases: RichardsonLucy
Richardson–Lucy deconvolution accelerated by vector extrapolation.
The iteration ψ of RichardsonLucy
(same model, start, stopping rule, blocks and extensions) is applied
to a point predicted from the last two iterates (Biggs and Andrews
1997, "technique II"):
yₖ = xₖ + αₖ hₖ, hₖ = xₖ − xₖ₋₁,
xₖ₊₁ = yₖ + gₖ, gₖ = ψ(yₖ) − yₖ,
with the acceleration parameter
αₖ = ∑ gₖ₋₁ · gₖ₋₂ / ∑ gₖ₋₂ · gₖ₋₂, 0 ≤ αₖ ≤ 1,
the least-squares projection of the latest change on the one before (first-order extrapolation, Eq. 10). The safeguards of the paper: αₖ < 0 is set to 0, which suspends the extrapolation until successive changes agree again; αₖ is capped at 1 so that the predicted step cannot grow exponentially; and the prediction is kept non-negative, negative pixels of yₖ being set to 0 (the paper requires the check but leaves the correction open). No extrapolation is made until two changes are known.
Start. From the uniform start, the first Richardson–Lucy update gives Hᵀy/Hᵀ1, the PSF-correlated data h ⋆ g that the paper uses as its starting image; the extrapolation history starts there, which also gives the paper's "few unaccelerated iterations" from a constant start. The first prediction is therefore made at the fourth update, and up to three iterations the result is plain Richardson–Lucy.
Acceleration factor. The estimated number of unaccelerated iterations equivalent to the accelerated ones, ∑ₖ ηₖ with
ηₖ = 1 + ∑ⱼ₌₁ᵏ ∏ₘ₌ₖ₋ⱼ₊₁ᵏ γₘ, γₖ = (αₖ βₖ)²,
βₖ = ∑ gₖ₋₁ · gₖ₋₂ / ∑ gₖ₋₁ · gₖ₋₁,
(Eqs. 11–13) is recorded in history.extras["effective_iterations"]
(per image with a global α, per block with a block-wise α).
Blocks and the scope of α. The sums of Eq. 10 run over the whole
image, as in the paper. An image larger than one block is then
processed in lockstep (alpha_scope="global"): every iteration is
one pass over its blocks, which read the data of their core and
halo and the current iterate around it from a full-size buffer,
make one step, write back their core and add their share of the
float64 sums; α and the χ² stopping test are evaluated once per
image and iteration. The halo covers the PSF, so the result is that
of the whole-image iteration. The iterates (three of them, on the
image extended by the PSF margin) are held in memory when they fit
the memory budget of config, else in temporary
files; the data are read once per iteration.
With alpha_scope="block", each block instead runs all its
iterations as an image of its own, with its own extrapolation
history and its own αₖ, in a single pass over the data (as for
RichardsonLucy); the results then
differ from the whole-image ones by up to about 10 % of the peak on
noisy data. alpha_scope="auto" uses the global α when each image
fits in one block and the block-wise α otherwise. The scope used for
each image is recorded in history.extras["alpha_scope"].
Stopping rule. Not specified in the paper, which compares restorations
at fixed iteration counts; the default is
Lucy's χ² rule of
RichardsonLucy, evaluated on the iterates
xₖ. Accelerated iterations amplify noise sooner, so the stopping rule or
n_iter matters more than for the plain iteration.
References
- Biggs DSC, Andrews M. Acceleration of iterative image restoration algorithms. Appl Opt 36(8):1766-1775, 1997. doi:10.1364/AO.36.001766
- Richardson WH. Bayesian-based iterative method of image restoration. J Opt Soc Am 62(1):55-59, 1972. doi:10.1364/JOSA.62.000055
- Lucy LB. An iterative technique for the rectification of observed distributions. Astron J 79(6):745-754, 1974. doi:10.1086/111605
BibTeX
@article{biggs1997acceleration,
author = {Biggs, David S. C. and Andrews, Mark},
title = {Acceleration of iterative image restoration
algorithms},
journal = {Applied Optics},
volume = {36},
number = {8},
pages = {1766--1775},
year = {1997},
doi = {10.1364/AO.36.001766}
}
@article{richardson1972bayesian,
author = {Richardson, William Hadley},
title = {Bayesian-Based Iterative Method of Image
Restoration},
journal = {Journal of the Optical Society of America},
volume = {62},
number = {1},
pages = {55--59},
year = {1972},
doi = {10.1364/JOSA.62.000055}
}
@article{lucy1974iterative,
author = {Lucy, L. B.},
title = {An iterative technique for the rectification of
observed distributions},
journal = {The Astronomical Journal},
volume = {79},
number = {6},
pages = {745--754},
year = {1974},
doi = {10.1086/111605}
}
Examples:
>>> import torch
>>> from optix.deconv import BiggsAndrews
>>> psf = torch.ones(5, 5)
>>> data = torch.poisson(torch.full((64, 64), 10.0))
>>> est = BiggsAndrews(psf, n_iter=10).fit(data)
>>> est.apply(data).shape
torch.Size([64, 64])
Configure the accelerated deconvolution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
psf
|
Tensor | None
|
See |
None
|
n_iter
|
Tensor | None
|
See |
None
|
alpha
|
Tensor | None
|
See |
None
|
max_iter
|
Tensor | None
|
See |
None
|
damping
|
float | None
|
See |
None
|
halo
|
float | None
|
See |
None
|
block
|
float | None
|
See |
None
|
alpha_scope
|
('global', block, auto)
|
Pixels over which the sums of the acceleration parameter αₖ (Eq.
10) run. |
"global"
|
faithful
|
bool
|
True
|
|
dtype
|
bool
|
True
|
|
device
|
bool
|
True
|
|
layout
|
bool
|
True
|
NagyOLeary
NagyOLeary(psf=None, centres=None, *, interpolation=None, precondition=None, tau=None, boundary=None, n_iter=None, halo=None, block=None, faithful=True, dtype=None, device=None, layout=None)
Bases: Estimator
Restoration with a spatially variant PSF (Nagy & O'Leary 1998).
Model: the image is the blur of the object by PSFs kᵢ measured at the nodes of a rectangular grid, combined after convolution,
g = K f + η, K = D₁ K₁ + ⋯ + Dₚ Kₚ (Eq. 2.1),
see NagyOLearyPSF. The object is
recovered by conjugate gradients on the least-squares problem
min ‖K f − g‖² (CGLS), regularised by stopping the iteration early,
and preconditioned by the block-diagonal circulant matrix Cτ (§4,
RegionPreconditioner):
on each region, the optimal circulant approximation of the blur by
that region's PSF (Chan & Olkin), with eigenvalues below τ replaced
by 1. As in the paper's experiments (§5), τ = 0. With
interpolation="linear" the preconditioner uses, on each region of
the piecewise-constant partition, the PSF of that region (§4.1.1:
one of the vertex kernels). precondition=False runs plain CGLS,
the paper's reference method. The paper's variants (interpolation,
precondition, tau) keep the estimator faithful.
Boundary. As in the paper (§1: K is square; §3.2.1: zero padding
along the exterior borders), the unknowns are the object pixels of
the image, and the object is zero outside it (boundary="zero").
The extension boundary="extended" instead solves for an object
extended past the image by the PSF support, as
RichardsonLucy does; the system is
then underdetermined, and early stopping selects the solution.
Blocks. Large inputs are processed in blocks with a halo, and
only the core of each block is kept. The blur weights are those of
the whole image (global positions), and the unknowns of a block are
its loaded pixels plus the image pixels within the PSF support
around them (zero outside the image). Each block runs a complete
CGLS on its own least-squares problem, with its own inner products
and step sizes, and the preconditioner of a block uses the parts of
the regions that fall in it. Since the step sizes depend on the
data and the iteration count sets the regularisation, each block is
regularised differently: the block-wise result is a valid CG
restoration, but not the whole-image CG iterate. With Gaussian PSFs
and blocks of 16–32 pixels, the two differ by 10–30 % (relative L2
norm), while both are about as close to the true object. With the
default block, the image is processed whole when it fits in the
memory budget.
Cost. A product with K is a sum of T full-block convolutions, T the number of PSFs whose weights meet the block, so the operator stores T weight maps and T transfer functions per block, and each product costs T FFT pairs. The paper's region-by-region products (§3.2.1) give the same result with about the storage of one spatially invariant convolution. The memory budget accounts for the T terms.
Smooth PSFs need τ > 0
The paper's experiments use τ = 0 (§5), and §4 notes that "for
moderately ill-posed problems with little noise, we can take
τ ≈ 0". A likely reason why this works there is that the HST
PSFs have a sharp core, which keeps the eigenvalues of C away
from 0; the paper does not say so. For smooth PSFs (e.g.
Gaussian), the eigenvalues of C decay to tiny values, and Cτ⁻¹
with τ = 0 amplifies the mismatch between C and K at the region
boundaries, even without noise: PCG then diverges from the first
iterations. Choose τ ≈ 0.1–0.3 of the largest eigenvalue (≈ 1 for
unit-sum PSFs), the larger values for wider PSFs; with smaller
τ the first iterates can still overshoot. With Gaussian PSFs
(σ = 0.7–2 pixels) and such τ, PCG after 14 iterations is about
as accurate as plain CG or somewhat worse (relative error 0–30 %
higher on a checkerboard object), not better: the speed-up of §5
should not be expected for smooth PSFs (the paper notes
something similar for smooth images, §5).
precondition=False avoids the issue.
Choices not specified in the paper
- The paper avoids a stopping criterion and compares solutions
after a fixed number of iterations: 14 PCG iterations in
Fig. 5.8, the default
n_iter. - CGLS starts from f⁽⁰⁾ = 0. Object pixels outside the
piecewise-constant regions of a block (outside the image with
boundary="extended", or in the margin around an inner block) are not preconditioned. - Region boundaries are half-way between neighbouring centres.
References
- Nagy JG, O'Leary DP. Restoring images degraded by spatially variant blur. SIAM J Sci Comput 19(4):1063-1082, 1998. doi:10.1137/S106482759528507X
BibTeX
@article{nagy1998restoring,
author = {Nagy, James G. and O'Leary, Dianne P.},
title = {Restoring Images Degraded by Spatially Variant
Blur},
journal = {SIAM Journal on Scientific Computing},
volume = {19},
number = {4},
pages = {1063--1082},
year = {1998},
doi = {10.1137/S106482759528507X}
}
Examples:
>>> import torch
>>> from optix.deconv import NagyOLeary
>>> psf = torch.ones(2, 2, 5, 5) # 2 × 2 grid of 5 × 5 PSFs
>>> data = torch.rand(64, 64)
>>> est = NagyOLeary(psf, [[16, 48], [16, 48]]).fit(data)
>>> est.apply(data).shape
torch.Size([64, 64])
Configure the restoration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
psf
|
Tensor
|
PSFs |
None
|
centres
|
sequence of 1-D tensors
|
Position of the grid nodes along each spatial axis, in pixels. |
None
|
interpolation
|
(constant, linear)
|
Weights of the blur model (see
|
"constant"
|
precondition
|
bool
|
Preconditioned CG (PCG) or plain CG (both from the paper). Default: True. |
None
|
tau
|
float
|
Truncation level τ of the preconditioner (§4). Default (§5): 0. Smooth PSFs need τ > 0 (see the warning above). |
None
|
boundary
|
(zero, extended)
|
Unknowns on the image with a zero object outside it (paper, default), or an object extended past the image by the PSF support (extension). |
"zero"
|
n_iter
|
int
|
Number of CG iterations. Default: 14 (see above). |
None
|
halo
|
int or sequence of int
|
Halo width per spatial axis, at least the PSF size. Default: twice the PSF size (not specified in the paper). |
None
|
block
|
sequence of int or None
|
Core block size per spatial axis. Default: from the memory budget. |
None
|
faithful
|
bool
|
See |
True
|
dtype
|
bool
|
See |
True
|
device
|
bool
|
See |
True
|
layout
|
bool
|
See |
True
|
MultiviewRL
MultiviewRL(psfs=None, *, kernel=None, update=None, n_iter=None, weights=None, weight_sum=None, chi2_stop=None, alpha=None, max_iter=None, halo=None, block=None, faithful=True, dtype=None, device=None, layout=None)
Bases: Estimator
Multiview Richardson–Lucy deconvolution of registered views.
The efficient Bayesian-based multiview deconvolution of Preibisch et al. 2014, and its variants.
Model (Supplementary Note 1.2, Eqs. 12–15). N views y₁, …, y_N of one object f, already registered and resampled onto a common grid, each blurred by its own PSF Sᵥ (normalised to unit sum, in the coordinates of that grid):
yᵥ ~ Poisson(Hᵥ f), (Hᵥ f)ᵢ = ∑ⱼ Sᵥ(i − j) fⱼ.
Bayesian-based multiview iteration (Eqs. 36–37). From Bayes' theorem, without assuming that the views are independent (Supplementary Note 3), the update of the object is the pixel-wise product of the single-view Richardson–Lucy corrections,
f⁽ʳ⁺¹⁾ = f⁽ʳ⁾ ∏ᵥ cᵥ, cᵥ = Hᵥᵀ[yᵥ / Hᵥ f⁽ʳ⁾] / Hᵥᵀ1,
normalised by the |V|-th root (geometric mean, Eqs. 46–47) for the convergence proof to the maximum-likelihood solution (Supplementary Note 2). The product suggests applying the corrections one view after the other, each at the current estimate (sequential updates, Supplementary Note 5, Eqs. 104–107 and 109–112): ordered-subset EM (Hudson & Larkin 1994) with one view per subset, which converges about N times faster.
Efficient Bayesian-based iteration (Supplementary Note 4). The conditional probability of what a view w sees, given an observation in view v, defines "virtual" views φᵥ^{V_w} ≈ yᵥ ∗ Pᵥ* ∗ P_w (Eq. 77). Adding their updates (Eq. 86) and approximating (f ∗ g)·(f ∗ h) ≈ f ∗ (g·h) (Eq. 91) folds them into the back projection of view v: the mirrored PSF Pᵥ* (Pᵥ = Sᵥ, P*(ξ) = P(−ξ)) is replaced by the compound kernel (Eqs. 102–103)
Pᵥ^compound = Pᵥ* · ∏_{w ≠ v} Pᵥ* ∗ P_w ∗ P_w*,
at no extra cost per iteration. The ad hoc simplifications of
Supplementary Note 6 sharpen the virtual views further:
optimisation I drops the convolution with P_w* (Eq. 114), and
optimisation II assumes P_w constant, which leaves (Pᵥ*)ᴺ (Eq. 115).
See compound_kernels.
With one view every variant is the Richardson–Lucy iteration of
RichardsonLucy.
Notation: f, yᵥ, Sᵥ and Hᵥᵀ are ψ, φᵥ, Pᵥ and the convolution with Pᵥ* of the paper.
Faithful default. The efficient Bayesian-based kernels (Eq. 102) with sequential updates (Eqs. 104–107), the method the paper derives and names; optimisations I and II, the plain Bayesian-based kernels and the combined updates are the variants it benchmarks (Supplementary Note 7.1). One iteration is one pass over all the views (Supplementary Note 7.1); the number of iterations is the only parameter of the method, chosen by the user. The starting estimate is the constant image of the mean intensity of the views (Eq. 11).
Weights (Online Methods, Eq. 3). Views that cover only part of the
sample are blended with weights wᵥ(ξ) ∈ [0, 1] (e.g. a cosine fall-off
near the view borders): the sequential update of view v applies the
fraction wᵥ of its correction, f ← f · (1 − wᵥ + wᵥ cᵥ). Weights are
normalised per pixel to sum to weight_sum over the views, each one
capped at 1, wᵥ ← min(1, k wᵥ / ∑ᵤ wᵤ) (0 where all vanish). k = 1
(the default) updates every pixel by one full correction per
iteration; k > 1 trades uniformity for the ordered-subset speed-up
(Supplementary Fig. 10). Beyond the field of view the weights are
carried over by back projection (see
Multiview; not specified in the
paper). The weights gate the update only, so a view's missing pixels
count as observed zeros within a PSF half-width of its coverage: the
fall-off should be at least as wide as the PSF.
Blocks. As RichardsonLucy: the
object is estimated on a domain padded by the PSF support, and large
inputs are processed in halo blocks, the same region of every view at
once. The PSFs are zero-padded to a common shape with odd sizes.
Sample and group axes are iterated over; the views share one layout.
Extensions (off by default)
- χ² stop:
chi2_stop=Truereplaces the fixed number of iterations by the test of Lucy (1974) on all views: stop once P(χ² > χ²_obs) ≥alpha, with χ²_obs = ∑ᵥ ∑ᵢ (yᵥᵢ − μᵥᵢ)²/μᵥᵢ, μᵥ = Hᵥ f, and ν = N |Ω| − 1 degrees of freedom (|Ω| pixels per view), capped atmax_iter. The test assumes counts.
Approximations
The virtual views rest on Q(ξ|xᵥ) ≈ P(xᵥ|ξ) (Eq. 76) and on Eq. 91, which hold for Gaussian-like PSFs; the convergence proof (Supplementary Note 2) covers the Bayesian-based kernels only. Views must be registered beforehand, and the PSFs given in the orientation of the common grid; neither is estimated here.
References
- Preibisch S, Amat F, Stamataki E, Sarov M, Singer RH, Myers E, Tomancak P. Efficient Bayesian-based multiview deconvolution. Nat Methods 11(6):645-648, 2014. doi:10.1038/nmeth.2929
- Hudson HM, Larkin RS. Accelerated image reconstruction using ordered subsets of projection data. IEEE Trans Med Imaging 13(4):601-609, 1994. doi:10.1109/42.363108
- Shepp LA, Vardi Y. Maximum likelihood reconstruction for emission tomography. IEEE Trans Med Imaging 1(2):113-122,
- doi:10.1109/TMI.1982.4307558
BibTeX
@article{preibisch2014efficient,
author = {Preibisch, Stephan and Amat, Fernando and
Stamataki, Evangelia and Sarov, Mihail and
Singer, Robert H. and Myers, Eugene and
Tomancak, Pavel},
title = {Efficient {Bayesian}-based multiview
deconvolution},
journal = {Nature Methods},
volume = {11},
number = {6},
pages = {645--648},
year = {2014},
doi = {10.1038/nmeth.2929}
}
@article{hudson1994accelerated,
author = {Hudson, H. Malcolm and Larkin, Richard S.},
title = {Accelerated image reconstruction using ordered
subsets of projection data},
journal = {IEEE Transactions on Medical Imaging},
volume = {13},
number = {4},
pages = {601--609},
year = {1994},
doi = {10.1109/42.363108}
}
@article{shepp1982maximum,
author = {Shepp, Lawrence A. and Vardi, Yehuda},
title = {Maximum likelihood reconstruction for emission
tomography},
journal = {IEEE Transactions on Medical Imaging},
volume = {1},
number = {2},
pages = {113--122},
year = {1982},
doi = {10.1109/TMI.1982.4307558}
}
Examples:
>>> import torch
>>> from optix.deconv import MultiviewRL
>>> psfs = [torch.ones(1, 5), torch.ones(5, 1)]
>>> views = [torch.poisson(torch.full((32, 32), 10.0)) for _ in psfs]
>>> mv = MultiviewRL(psfs, n_iter=5).fit(views)
>>> mv.apply(views).shape
torch.Size([32, 32])
Configure the deconvolution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
psfs
|
sequence of Tensor
|
PSF of each view, |
None
|
kernel
|
(efficient, bayesian, optimization - 1, optimization - 2)
|
Back-projection kernels (see
|
"efficient"
|
update
|
(sequential, multiplicative, additive)
|
Combination of the views (see
|
"sequential"
|
n_iter
|
int
|
Number of iterations (passes over all views). Default: 10 (not specified in the paper, where the user chooses it). |
None
|
weights
|
sequence of array-like
|
Weight wᵥ ≥ 0 of each view (Eq. 3), |
None
|
weight_sum
|
float
|
Sum k of the weights over the views after normalisation. Default: 1 (Online Methods). |
None
|
chi2_stop
|
bool
|
Extension: stop by the χ² test instead of after |
None
|
alpha
|
float
|
Level of the χ² test (with |
None
|
max_iter
|
int
|
Iteration cap of the χ² test. Default: 100 (not specified in the papers). |
None
|
halo
|
int or sequence of int
|
Halo width per spatial axis, at least the (common) PSF size. Default: twice the PSF size (not specified in the paper). |
None
|
block
|
sequence of int or None
|
Core block size per spatial axis (None entries: whole extent). Default: chosen from the memory budget. |
None
|
faithful
|
bool
|
See |
True
|
dtype
|
bool
|
See |
True
|
device
|
bool
|
See |
True
|
layout
|
bool
|
See |
True
|
kernels
kernels(**backend)
Back-projection kernel of each view, (*K), unit sum.
See compound_kernels.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**backend
|
object
|
|
{}
|
Returns:
| Type | Description |
|---|---|
list of Tensor
|
|
fit
fit(data, *, layout=None, init=None, callback=None, verbose=False)
Prepare the deconvolution of registered views.
One pass over the views computes the starting level of each image (sample/group index): the mean intensity of all views.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
sequence of array-like or Labeled
|
Views, one per PSF, all of the same shape ( |
required |
layout
|
Layout
|
Axis roles, shared by the views. |
None
|
init
|
object
|
Unused. |
None
|
callback
|
object
|
Unused. |
None
|
verbose
|
object
|
Unused. |
None
|
Returns:
| Type | Description |
|---|---|
MultiviewRL
|
self. |
apply
apply(data, out=None)
Deconvolve the views into one image.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
sequence of array-like or Labeled
|
The views given to |
required |
out
|
writable array-like
|
Output, the shape of one view (tensor, numpy, zarr, ...). Default: a new tensor. |
None
|
Returns:
| Type | Description |
|---|---|
writable array-like
|
|
Wiener
Wiener(psf=None, *, nsr=None, boundary=None, halo=None, block=None, faithful=True, dtype=None, device=None, layout=None)
Bases: _LinearDeconvolution
Wiener deconvolution with a known PSF, block by block.
Model: the image is the blurred object plus noise, y = H f + n, with (H f)ᵢ = ∑ⱼ S(i − j) fⱼ and S the point spread function (normalised to unit sum, so that |H(ν)| ≤ 1 and H(0) = 1). The Wiener filter is the linear estimate of minimum mean squared error for a stationary object and noise; in the frequency domain,
F̂(ν) = H*(ν) Y(ν) / (|H(ν)|² + K(ν)), K(ν) = Sₙ(ν) / S_f(ν),
with Sₙ and S_f the power spectra of the noise and of the object.
When they are unknown, K is a constant noise-to-signal ratio, tuned
by hand. K → 0 gives the inverse filter Y / H; a larger K suppresses
the frequencies at which the PSF transmits little, trading
resolution for noise. With a constant K, the filter equals the
zero-order Tikhonov filter with λ = K (see
Tikhonov).
The result is linear in the data: it may be negative and has noise
correlated over the PSF scale. It is a fast preview, or a starting
point for iterative methods such as
RichardsonLucy.
Boundaries and blocks. The filter is applied by FFT, which treats
the image as periodic. With boundary="taper" (the default), each
block (core plus halo) is extended past each edge by its mirror
image over the halo width, and the two reflections are joined by a
raised-cosine blend over at least the PSF size (see
smooth_periodic_extension),
so its periodic continuation has no jump and the edges do not ring;
only the core of each block is kept. The halo is at least the PSF
size (default: twice). The filter is linear and its impulse response
decays away from the origin, so the block-wise result approaches the
whole-image one (with the same halo, which also sets the mirror
width at the image edges) geometrically as the halo grows; the
residual difference is larger for weaker regularisation, whose
impulse response is longer.
With boundary="periodic", each block is filtered as a periodic
image of its own, without extension: on a single block (the whole
image), this exactly inverts a circular blur.
Images are independent: sample and group axes of the layout are iterated over, the spatial axes (as many as the PSF has dims, in layout order) are deconvolved, in one pass over the data.
Extensions (off by default)
- Camera model:
fit(data, init=sensor)with aSensorEstimateconverts the data to electrons, (y − offset)/gain, before deconvolution; the result is then in electrons.
References
- Gonzalez RC, Woods RE. Digital Image Processing, chapter "Image Restoration and Reconstruction". Pearson.
- Bertero M, Boccacci P. Introduction to Inverse Problems in Imaging. IOP Publishing, 1998.
BibTeX
@book{gonzalez2018digital,
author = {Gonzalez, Rafael C. and Woods, Richard E.},
title = {Digital Image Processing},
edition = {4},
publisher = {Pearson},
year = {2018}
}
@book{bertero1998introduction,
author = {Bertero, Mario and Boccacci, Patrizia},
title = {Introduction to Inverse Problems in Imaging},
publisher = {IOP Publishing},
year = {1998}
}
Examples:
>>> import torch
>>> from optix.deconv import Wiener
>>> psf = torch.ones(5, 5)
>>> data = torch.rand(64, 64)
>>> Wiener(psf, nsr=1e-2).fit(data).apply(data).shape
torch.Size([64, 64])
Configure the filter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
psf
|
Tensor
|
Point spread function, |
None
|
nsr
|
float or callable
|
Noise-to-signal ratio K ≥ 0. A callable is K(ν): it receives
the frequencies of the block's spectrum (one tensor per
spatial axis, in cycles per pixel, as returned by
|
None
|
boundary
|
(taper, periodic)
|
Extension of each block before the FFT (see above). Default: "taper". |
"taper"
|
halo
|
int or sequence of int
|
Halo width per spatial axis, at least the PSF size along that axis. Default: twice the PSF size. |
None
|
block
|
sequence of int or None
|
Core block size per spatial axis (None entries: whole extent). Default: chosen from the memory budget. |
None
|
faithful
|
bool
|
See |
True
|
dtype
|
bool
|
See |
True
|
device
|
bool
|
See |
True
|
layout
|
bool
|
See |
True
|
Tikhonov
Tikhonov(psf=None, *, lam=None, operator=None, boundary=None, halo=None, block=None, faithful=True, dtype=None, device=None, layout=None)
Bases: _LinearDeconvolution
Tikhonov-regularised deconvolution with a known PSF, block by block.
Model: y = H f + n, with (H f)ᵢ = ∑ⱼ S(i − j) fⱼ and S the point spread function (normalised to unit sum). The estimate minimises
‖y − H f‖² + λ ‖L f‖²,
with L the identity (zero-order Tikhonov regularisation, a penalty on the energy of f) or the discrete Laplacian (a penalty on its roughness, as in constrained least-squares filtering). Both H and L are convolutions, so the minimiser is, in the frequency domain,
F̂(ν) = H*(ν) Y(ν) / (|H(ν)|² + λ |L(ν)|²),
with |L(ν)|² = 1 for the identity and (∑ₐ 4 sin²(π νₐ))² for the
Laplacian (see laplacian_power).
λ → 0 gives the inverse filter; a larger λ suppresses noise at the
cost of resolution. With the Laplacian, the mean of the image
(ν = 0) is not penalised and is preserved; with the identity, it is
scaled by 1/(1 + λ).
The result is linear in the data and may be negative.
Boundaries and blocks. The filter is applied by FFT, which treats
the image as periodic. With boundary="taper" (the default), each
block (core plus halo) is extended past each edge by its mirror
image over the halo width, and the two reflections are joined by a
raised-cosine blend over at least the PSF size (see
smooth_periodic_extension),
so its periodic continuation has no jump and the edges do not ring;
only the core of each block is kept. The halo is at least the PSF
size (default: twice). The filter is linear and its impulse response
decays away from the origin, so the block-wise result approaches the
whole-image one (with the same halo, which also sets the mirror
width at the image edges) geometrically as the halo grows; the
residual difference is larger for weaker regularisation, whose
impulse response is longer.
With boundary="periodic", each block is filtered as a periodic
image of its own, without extension: on a single block (the whole
image), this exactly inverts a circular blur.
Images are independent: sample and group axes of the layout are iterated over, the spatial axes (as many as the PSF has dims, in layout order) are deconvolved, in one pass over the data.
Extensions (off by default)
- Camera model:
fit(data, init=sensor)with aSensorEstimateconverts the data to electrons, (y − offset)/gain, before deconvolution; the result is then in electrons. -
Automatic λ:
lam="gcv"picks λ by generalised cross-validation (Golub, Heath & Wahba 1979) atfit: the influence matrix A has eigenvalues r(ν) = |H(ν)|² / (|H(ν)|² + λ |L(ν)|²) on each block's FFT grid, andV(λ) = n ∑ |(1 − r) Y|² / (∑ (1 − r))²,
summed over the frequencies of all blocks (the blocks without
halo, each extended as above) and all images, is minimised
over λ ∈ [10⁻¹⁰, 10²] on a grid of four values per decade.
This selection rule is not part of the references above; it
is a generic choice. The chosen value is strength; a value
at either end of the grid is flagged with a warning.
References
- Gonzalez RC, Woods RE. Digital Image Processing, chapter "Image Restoration and Reconstruction". Pearson.
-
Bertero M, Boccacci P. Introduction to Inverse Problems in Imaging. IOP Publishing, 1998.
-
Golub GH, Heath M, Wahba G. Generalized cross-validation as a method for choosing a good ridge parameter. Technometrics 21(2):215-223, 1979. doi:10.1080/00401706.1979.10489751
BibTeX
@book{gonzalez2018digital,
author = {Gonzalez, Rafael C. and Woods, Richard E.},
title = {Digital Image Processing},
edition = {4},
publisher = {Pearson},
year = {2018}
}
@book{bertero1998introduction,
author = {Bertero, Mario and Boccacci, Patrizia},
title = {Introduction to Inverse Problems in Imaging},
publisher = {IOP Publishing},
year = {1998}
}
@article{golub1979generalized,
author = {Golub, Gene H. and Heath, Michael and
Wahba, Grace},
title = {Generalized Cross-Validation as a Method for
Choosing a Good Ridge Parameter},
journal = {Technometrics},
volume = {21},
number = {2},
pages = {215--223},
year = {1979},
doi = {10.1080/00401706.1979.10489751}
}
Examples:
>>> import torch
>>> from optix.deconv import Tikhonov
>>> psf = torch.ones(5, 5)
>>> data = torch.rand(64, 64)
>>> Tikhonov(psf, lam=1e-2, operator="laplacian").fit(data).apply(
... data
... ).shape
torch.Size([64, 64])
Configure the filter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
psf
|
Tensor
|
Point spread function, |
None
|
lam
|
float or gcv
|
Regularisation weight λ ≥ 0, or |
None
|
operator
|
(identity, laplacian)
|
Regularisation operator L. Default: "identity". |
"identity"
|
boundary
|
(taper, periodic)
|
Extension of each block before the FFT (see above). Default: "taper". |
"taper"
|
halo
|
int or sequence of int
|
Halo width per spatial axis, at least the PSF size along that axis. Default: twice the PSF size. |
None
|
block
|
sequence of int or None
|
Core block size per spatial axis (None entries: whole extent). Default: chosen from the memory budget. |
None
|
faithful
|
bool
|
See |
True
|
dtype
|
bool
|
See |
True
|
device
|
bool
|
See |
True
|
layout
|
bool
|
See |
True
|
Ikoma
Ikoma(psf=None, *, nu=None, regulariser=None, rho=None, max_iter=None, tol=None, psf_norm=None, weights=None, halo=None, block=None, faithful=True, dtype=None, device=None, layout=None)
Bases: _Variational
Shifted-Poisson deconvolution with a Hessian prior (Ikoma et al. 2018).
Model (Eqs. 3–4). In electrons, after dark-field and flat-field correction and division by the gain g, the data are
ỹ = Poisson(A x) + N(0, σ̃²), σ̃² = σ²/g²,
with A the 3-D convolution with the PSF, approximated by the shifted Poisson model ỹ + σ̃² ~ Poisson(A x + σ̃²), which has the same mean and variance. The estimate solves (Eq. 5, SI Eq. S8)
minimise_x ∑_{j∈C} (A x)ⱼ − (ỹⱼ + σ̃²) log((A x)ⱼ + σ̃²)
+ ν ∑_{j∈Ω} ‖(H x)ⱼ‖₂ subject to x ≥ 0,
where H x packs the six (three in 2-D) distinct second differences of x, the off-diagonal ones times √2 (SI Eq. S7), so ‖(H x)ⱼ‖₂ is the Frobenius norm of the Hessian at voxel j. Second differences compose forward differences, D_ab = D_a D_b (SI Eq. S5). The data are clipped at −σ̃² so that the fidelity is convex (SI §B).
Unknown boundary. x lives on a grid N larger than the observed block (N > M), and the fidelity sums over the observed voxels C only, so that light from outside the field of view is modelled (Eq. 5). The grid is N = L + K − 1 (L the block, K the PSF), rounded up to a fast FFT size (not specified in the paper); the convolution and the differences are periodic on it, and Ω is the whole grid.
Solver (SI §E). ADMM with the splits z₁ = A x, z₂ = x,
z₃ = H x and one penalty ρ (see
admm_fft): the x-update is solved in the
Fourier domain (Eq. S16), z₁ by the closed-form shifted-Poisson
prox on C and z₁ = A x + u₁ outside C (Eq. S17), z₂ by projection
onto x ≥ 0 (Eq. S18), z₃ by block soft thresholding at ν/ρ
(Eq. S19). All variables start at 0; ρ = 6000ν / max(ỹ)
(ρ = 6 / max(ỹ) without a regulariser); the iterations stop when
‖xᵏ⁺¹ − xᵏ‖₂ < 10⁻³ ‖xᵏ‖₂ or after 150 iterations. The result is x
restricted to the observed voxels (the paper does not say whether
x or z₂ is returned); it is not projected onto x ≥ 0.
The stopping rule is part of the method. With the paper's ρ
rule, tolerance and iteration cap, the result is an early-stopped
ADMM iterate, not the minimiser of the objective above. On
simulated 2-D data (γ = 2, σ = 3, peaks of 10 to 1000
photoelectrons) it is about 25 to 34 % (relative ℓ2) away from the
minimiser, and its SNR is about 1.9 to 4.3 dB higher; 13 to 26 % of its
voxels are negative, by less than 0.4 % of the peak. The stop
therefore regularises too: the result depends on tol, max_iter
and rho, not only on ν, and tightening tol with the default ν
lowers the SNR. Each solve records its number of iterations, last
relative change and last primal and dual residuals in
history.extras ("iterations", "change", "primal_residual",
"dual_residual"); the residuals tend to 0 only at convergence.
PSF. Normalised so that each xy-plane (the last two spatial
axes) sums to 1 (SI §H): x is then in photoelectrons per exposure
of one image of the focal stack. This normalisation assumes that
every plane of the PSF carries the same energy (as for a widefield
PSF); psf_norm="sum" normalises to unit sum instead (the optix
convention). For a PSF of K_z planes of equal energy the two give
x_plane = x_sum / K_z and ν_plane = K_z ν_sum. A PSF as large as the
stack (as simulated in the paper) doubles the grid: crop it to its
support.
Regularisation weight ν. The paper tunes ν per data set (it scans 0.005–0.100 on its experimental stacks) and gives no default. The default here is not in the paper:
ν = κ · ∑S / q₉₉.₉(ỹ), κ = 0.1,
per image, with q₉₉.₉(ỹ) the 99.9th percentile of the prepared
data (computed exactly in the single pass of fit; unlike max ỹ, a
hot pixel or a single bright bead barely changes it) and ∑S the sum
of the normalised PSF (1 for psf_norm="sum", the number of planes
for "plane"). The 1/peak scaling is that of a MAP estimate with a
prior on the normalised image x̂ = x/s (s the peak) that is the same
at every photon count, −log p(x̂) = κ‖H x̂‖ + const: the objective
ℓ(x; ỹ) + κ‖H x̂‖ is ℓ(x; ỹ) + (κ/s)‖H x‖, so ν = κ/s. The rule does
not use σ̃²; with read noise the shifted-Poisson likelihood is not
homogeneous in s (the Poisson one is, ℓ(s x̂; s ŷ) = s ℓ(x̂; ŷ) up
to a constant), so it is an approximation there. The ∑S factor makes
the default the same for both PSF normalisations.
κ was calibrated for the default stopping rule (the paper's
tol, max_iter and ρ rule) and is not valid with other values of
them. Calibration data: blobs, filaments and their mixture, 2-D and
3-D, Gaussian and Gaussian-beam PSFs, peaks of 10, 100 and 1000
photoelectrons, γ = 2, σ = 3 as in the paper's simulation, three
seeds each (54 cases). There, κ = 0.1 minimises the mean loss of SNR
against the best ν of a fine grid: 1.2 dB on average, 4.8 dB in the
worst case. The loss comes from the image content: smooth blobs
want a larger ν (best κ up to 0.5), thin filaments a smaller one
(best κ ≈ 0.006 to 0.03). In 6 of the 54 cases (2-D blobs at 1000
and 2-D filaments at 100 photoelectrons) the default is 0.6 to
1.1 dB below no regulariser at all. Pass nu to set the weight;
the values used are in nu and rho after fit.
Camera calibration. From the estimates given to fit
(init=sensor, init=shading or both), which describe the raw
data:
SensorEstimate: ỹ = (y − offset)/gain, σ̃² = variance/gain² (maps allowed). The paper estimates g and σ with Foi's method (seeoptix.sensor). Without one, the data are taken in electrons with σ̃² = 0 (Poisson).ShadingEstimate: the dark field d (which includes the camera offset) is subtracted in place of the offset, and the data are divided by the flat field f, rescaled to unit median as in the paper's Methods, before the division by the gain: ỹ = (y − d)/(f·gain). The read-noise variance of the corrected data is then σ̃² = variance/(f·gain)²; with f ≡ 1 this is the paper's model. The shot noise of the corrected data, of variance (A x)/f, is still modelled as A x (the paper's approximation). A per-frame baseline is ignored.
Blocks. An image that fits in the memory budget is solved
whole. A larger one is cut into blocks with a halo (default: twice
the PSF size, not specified in the paper), each solved as an image
of its own with the unknown boundary, keeping its core; ν and ρ are
those of the whole image. The ADMM x-update is a global solve, so
the block-wise result is not the whole-image one near the seams; a
RuntimeWarning says when an image is split. The memory of a
block is counted on its FFT grid N (the loaded block plus the PSF,
rounded up), about 21 + 2.5·C buffers per grid voxel, with C the
number of regulariser components (6 for the 3-D Hessian). When the
budget only allows blocks whose core is less than a quarter of the
loaded block, apply raises a ValueError that gives the memory a
whole-image solve needs. halo and block are memory settings:
they do not change is_faithful. Sample and group axes are iterated
over.
Paper notation: ỹ, σ̃, A, H, ν, ρ as here; the PSF is h.
Variants and extensions
regulariser="none"(shifted Poisson with x ≥ 0 only) and, with σ̃² = 0, the Poisson model are the paper's comparison variants of Table 1 (ρ = 6/max ỹ).regulariser="tv"(isotropic total variation, also in Table 1) uses ρ = 6000ν/max ỹ, which is not specified in the paper; it is an extension.weights=(w₁, …, w_d): per-axis derivative weights, Dₐ replaced by wₐDₐ, for anisotropic sampling (the paper notes this is possible but uses unit weights), e.g. wₐ = min(spacing)/spacingₐ.psf_norm="sum": unit-sum PSF (see above).
References
- Ikoma H, Broxton M, Kudo T, Wetzstein G. A convex 3D deconvolution algorithm for low photon count fluorescence imaging. Sci Rep 8:11489, 2018. doi:10.1038/s41598-018-29768-x
BibTeX
@article{ikoma2018convex,
author = {Ikoma, Hayato and Broxton, Michael and Kudo,
Takamasa and Wetzstein, Gordon},
title = {A convex {3D} deconvolution algorithm for low
photon count fluorescence imaging},
journal = {Scientific Reports},
volume = {8},
pages = {11489},
year = {2018},
doi = {10.1038/s41598-018-29768-x}
}
Attributes:
| Name | Type | Description |
|---|---|---|
nu |
Tensor
|
Regularisation weight ν per image |
rho |
Tensor
|
ADMM penalty ρ per image, after |
peak |
Tensor
|
max ỹ per image (used by the ρ rule). |
robust_peak |
Tensor
|
99.9th percentile q₉₉.₉(ỹ) per image (used by the default ν). |
Examples:
>>> import torch
>>> from optix.deconv import Ikoma
>>> psf = torch.ones(5, 5)
>>> data = torch.poisson(torch.full((32, 32), 10.0))
>>> Ikoma(psf, max_iter=5).fit(data).apply(data).shape
torch.Size([32, 32])
Configure the deconvolution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
psf
|
Tensor
|
Point spread function, |
None
|
nu
|
float
|
Regularisation weight ν ≥ 0. Default: 0.1·∑S / q₉₉.₉(ỹ) per
image (see above; not in the paper, calibrated for the
default |
None
|
regulariser
|
(hessian, tv, none)
|
Penalty: Frobenius norm of the Hessian (default, the paper's method), isotropic total variation (extension), or none. |
"hessian"
|
rho
|
float
|
ADMM penalty ρ > 0. Default (paper): 6000ν / max ỹ per image (6 / max ỹ without a regulariser). |
None
|
max_iter
|
int
|
Maximum number of iterations. Default (paper): 150. |
None
|
tol
|
float
|
Relative-change tolerance. Default (paper): 10⁻³. |
None
|
psf_norm
|
(plane, sum)
|
PSF normalisation: each xy-plane sums to 1 (default, paper) or the whole PSF does (extension). |
"plane"
|
weights
|
sequence of float
|
Extension. Per-axis derivative weights, in layout order. Default: none (unit weights). |
None
|
halo
|
int or sequence of int
|
Halo width per spatial axis, at least the PSF size along that
axis. Default: twice the PSF size (not specified in the
paper). A memory setting: does not change |
None
|
block
|
sequence of int or None
|
Core block size per spatial axis (None entries: whole
extent). Default: chosen from the memory budget, the whole
image when it fits. A memory setting: does not change
|
None
|
faithful
|
bool
|
See |
True
|
dtype
|
bool
|
See |
True
|
device
|
bool
|
See |
True
|
layout
|
bool
|
See |
True
|
HSPIRAL
HSPIRAL(psf=None, *, tau=None, p=None, variant=None, inner_iter=None, rho=None, max_iter=None, tol=None, boundary=None, halo=None, block=None, faithful=True, dtype=None, device=None, layout=None)
Bases: _Variational
Poisson deconvolution with a Hessian Schatten-norm prior (HSPIRAL).
Model (Lefkimmiatis & Unser 2013, Eqs. 1–3). The data are photon counts y ~ Poisson(K x), with K the convolution with the PSF and x ≥ 0. The estimate is the penalised maximum-likelihood solution of Eq. (12),
minimise_x ∑ⱼ (K x)ⱼ − yⱼ log (K x)ⱼ + τ ∑ⱼ ‖(H x)ⱼ‖_{S_p}
subject to x ≥ 0,
where (H x)ⱼ is the 2 × 2 Hessian matrix of x at pixel j and ‖·‖_{S_p}
the Schatten norm of order p (Eq. 5), the ℓ_p norm of its singular
values, which are the absolute eigenvalues of the symmetric Hessian:
the nuclear norm (p = 1, sum), the Frobenius norm (p = 2) or the
spectral norm (p = ∞, largest). The second differences are forward
stencils (Section IV: "defined as in [16]", Lefkimmiatis, Ward &
Unser 2013, Eq. 10; Hessian).
Solvers. The paper gives two ADMM algorithms for Eq. (12), with
the z-update first (Eqs. 18a–c; see
admm_fft, order="z-first"), one penalty
α and scaled duals s. Both start from x⁰ = y with zero duals, use
α = 60τ/M (Sections IV-A and IV-C) and stop when
‖xᵏ⁺¹ − xᵏ‖₂ ≤ 10⁻⁵ ‖xᵏ‖₂ or after 400 iterations (Section IV-B).
The result is xᵏ (the algorithms return x); it is not projected onto
x ≥ 0. Each solve records its number of iterations, last relative
change and last primal and dual residuals in history.extras.
- HSPIRAL1 (Algorithm 1,
variant=1, the default: the variant of the paper's restoration results, Sections IV-B to IV-D). Splits z₁ = K x and z₂ = x (Eqs. 24–25): z₁ by the closed-form Poisson prox (Eq. 27), z₂ = prox of (τ/α)‖H·‖₁,ₚ + ι_C (Eq. 28), x = (KᵀK + I)⁻¹(Kᵀ(z₁ − s₁) + z₂ − s₂) (Eq. 29, in the Fourier domain), then the dual updates (Eq. 23). The prox of Eq. (28) has no closed form: it is computed by 5 iterations (Section IV-B) of the dual algorithm of Lefkimmiatis, Ward & Unser (2013, Algorithm 2; seeprox_hessian_schattenandHessianSchatten), started from its dual of the previous ADMM iteration (Section III-C). H has the boundary of that paper (Eq. 10: half-sample mirror,Hessian(boundary="mirror")). - HSPIRAL2 (Algorithm 2,
variant=2). Splits z₁ = K x, z₂ = H x, z₃ = x (Eqs. 30–31): z₁ by Eq. (27), z₂ by the Schatten-norm prox (Proposition 1; closed forms of Eqs. 43–47, seeprox_schatten), z₃ by projection onto x ≥ 0 (Eq. 32), then the x-update (Eq. 42) in the Fourier domain, and the dual updates. The Fourier solve needs H periodic (D_ab = D_a D_b with wrap-around; Lefkimmiatis, Bourquard & Unser 2012, Eq. 21), so the two variants differ in the Hessian at the last two rows and columns of the block.
Boundary. The paper assumes periodic (or mirror) boundaries for
the FFT solve of Eqs. (29) and (42) and does not say which its
experiments use; the default here is periodic: the blur (and, for
HSPIRAL2, the differences) wrap around the block, as in a
circular-blur simulation. boundary="unknown" is an extension (not
in the paper): x lives on a larger grid (the block plus the PSF, as
in Ikoma), the Poisson term sums over the
observed pixels only, and x⁰ is the data continued smoothly over the
margin; it avoids wrap-around artefacts on real images and is the
default of the faithful=False preset.
Choices not specified in the paper.
- M in α = 60τ/M is the maximum intensity of the ground-truth image in the paper; here it is max(y) per image.
- p: the paper compares 1, 2 and ∞ with no default; p = 1 gave the best pooled PSNR in its Table I and is the default. All three are the paper's method.
- Dimension: the paper is 2-D. In 3-D both variants are unchanged,
with the 3 × 3 Hessian (6 components, ‖H‖² ≤ 144 for the step of
the inner algorithm of HSPIRAL1): p = 2 needs no eigenvalues, and
p ∈ {1, ∞} use the closed-form 3 × 3 eigen-decomposition of
prox_schatten. - HSPIRAL1 warm start: the inner algorithm restarts its momentum at every ADMM iteration (t₁ = 1, Ψ₁ = Ω from the previous iteration); the paper says only that its internal variables are initialised with those of the previous iteration.
-
The regularisation weight τ: the paper tunes τ per image for the best PSNR. The default here is
τ = κ / (q₉₉.₉(y) − q₅₀(y)), κ = 1.6,
per image, with q₉₉.₉(y) the 99.9th percentile of the data
(computed exactly in the one pass of fit; a hot pixel barely
changes it) and q₅₀(y) their median (from a uniform sample of 8192
pixels in the same pass, exact for smaller images). The
difference is a robust range of the signal above the background:
the Hessian ignores a constant, so it is the signal amplitude, not
the intensity, that sets the scale of the prior. The 1/scale
factor is that of a MAP estimate whose prior on the normalised
image x/s (s the signal scale) is the same at every photon count:
the Poisson log-likelihood is homogeneous, ℓ(s x̂; s ŷ) = s ℓ(x̂; ŷ)
up to a constant, so ℓ(x; y) + κ‖H x/s‖ has the weight τ = κ/s.
The rule needs q₉₉.₉(y) > q₅₀(y) (pass tau otherwise).
κ is a 2-D calibration. It was found with HSPIRAL2 (in 2-D both
variants have the same best κ: they minimise Eq. 12 with Hessians
that differ only at the last two rows and columns), for the
paper's α rule and stopping rule, on 2-D simulated images with
circular blur (Gaussian, σ_b = 2, 9 × 9;
uniform 7 × 7): blobs, filaments, their mixture and
piecewise-smooth scenes, peaks of 10, 100 and 1000 photons on a
constant background of 0, 1, 3 and 10 times the peak, 64 × 64
(two seeds) and 128 × 128 (one seed) pixels, 288 cases, against
a grid of τ (factor √2). Among the scales q₉₉.₉, q₉₉.₉ − q₁ and
q₉₉.₉ − q₅₀, the last gives the smallest mean and worst-case
loss; with q₉₉.₉ alone the best κ grows with the background (about
18 times from no background to 10 times the peak). The best κ
depends only weakly on the photon count for smooth content (blobs
and piecewise-smooth scenes: about 1.3 to 2.9 at every count) but
falls by up to 5 times for thin filaments between 10 and 1000
photons (about 1.6 to 0.3). With κ = 1.6 the PSNR is on
average 0.4 dB below that of the best τ of the grid (at most 2.4,
2.7 and 3.2 dB for p = 1, 2, ∞; the grid was searched with p = 1)
and at least 1.3 dB above that of the data (8 dB on average).
In 3-D the same κ was about 2 to 4 times too large for both
variants on the scenes tried (24 × 32 × 32, peaks 30 and 300:
0.55 to 1.24 dB below the best τ), so a smaller τ is worth trying
there. Pass tau to set the weight; the values used are in tau
and rho after fit.
Camera calibration (not in the paper, which takes photon
counts). With a SensorEstimate
given to fit, y = (data − offset)/gain; with a
ShadingEstimate, the dark field
is subtracted and the data are divided by the flat field (unit
median), as for Ikoma. The model is Poisson:
read noise is ignored, and negative values are set to 0. Without an
estimate the data are taken as photon counts.
Blocks. An image that fits in the memory budget is solved whole;
a larger one is cut into blocks with a halo (default: twice the PSF
size, not specified in the paper), each solved on its own with the
boundary above, keeping its core; τ and α are those of the whole
image. A RuntimeWarning says when an image is split. With the
periodic boundary each block wraps around, so seams are worse than
with boundary="unknown". halo and block are memory settings:
they do not change is_faithful.
Paper notation: K the blur (h here elsewhere), H the Hessian
(ℋ in the paper), τ, α, p as here; the paper's s are the scaled
duals u of admm_fft; the inner algorithm's Ω, Ψ, t are those of
prox_hessian_schatten.
References
- Lefkimmiatis S, Unser M. Poisson image reconstruction with Hessian Schatten-norm regularization. IEEE Trans Image Process 22(11):4314-4327, 2013. doi:10.1109/TIP.2013.2271852
- Lefkimmiatis S, Ward JP, Unser M. Hessian Schatten-norm regularization for linear inverse problems. IEEE Trans Image Process 22(5):1873-1888, 2013. doi:10.1109/TIP.2013.2237919
- Lefkimmiatis S, Bourquard A, Unser M. Hessian-based norm regularization for image restoration with biomedical applications. IEEE Trans Image Process 21(3):983-995, 2012. doi:10.1109/TIP.2011.2168232
BibTeX
@article{lefkimmiatis2013poisson,
author = {Lefkimmiatis, Stamatios and Unser, Michael},
title = {Poisson Image Reconstruction With {Hessian}
{Schatten}-Norm Regularization},
journal = {IEEE Transactions on Image Processing},
volume = {22},
number = {11},
pages = {4314--4327},
year = {2013},
doi = {10.1109/TIP.2013.2271852}
}
@article{lefkimmiatis2013hessian,
author = {Lefkimmiatis, Stamatios and Ward, John Paul and
Unser, Michael},
title = {{Hessian} {Schatten}-Norm Regularization for
Linear Inverse Problems},
journal = {IEEE Transactions on Image Processing},
volume = {22},
number = {5},
pages = {1873--1888},
year = {2013},
doi = {10.1109/TIP.2013.2237919}
}
@article{lefkimmiatis2012hessian,
author = {Lefkimmiatis, Stamatios and Bourquard, Aur{\'e}lien
and Unser, Michael},
title = {Hessian-Based Norm Regularization for Image
Restoration With Biomedical Applications},
journal = {IEEE Transactions on Image Processing},
volume = {21},
number = {3},
pages = {983--995},
year = {2012},
doi = {10.1109/TIP.2011.2168232}
}
Attributes:
| Name | Type | Description |
|---|---|---|
tau |
Tensor
|
Regularisation weight τ per image |
rho |
Tensor
|
ADMM penalty α per image, after |
peak |
Tensor
|
max y per image (M of the α rule). |
robust_peak |
Tensor
|
99.9th percentile q₉₉.₉(y) per image (used by the default τ). |
median |
Tensor
|
Median q₅₀(y) per image (used by the default τ), from a uniform sample of 8192 pixels (exact for smaller images). |
Examples:
>>> import torch
>>> from optix.deconv import HSPIRAL
>>> psf = torch.ones(5, 5)
>>> data = torch.poisson(torch.full((32, 32), 10.0))
>>> HSPIRAL(psf, max_iter=5).fit(data).apply(data).shape
torch.Size([32, 32])
Configure the deconvolution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
psf
|
Tensor
|
Point spread function, |
None
|
tau
|
float
|
Regularisation weight τ ≥ 0. Default: 1.6 / (q₉₉.₉(y) − q₅₀(y)) per image (see above; not in the paper). |
None
|
p
|
(1, 2, inf)
|
Order of the Schatten norm. Default: 1 (all three are the paper's method). |
1
|
variant
|
(1, 2)
|
HSPIRAL1 (default, the paper's experiments) or HSPIRAL2; both are faithful. |
1
|
inner_iter
|
int
|
Iterations of the inner prox of HSPIRAL1 per ADMM iteration.
Default (paper): 5. Unused by HSPIRAL2, where it does not
change |
None
|
rho
|
float
|
ADMM penalty α > 0. Default (paper): 60τ / max y per image. |
None
|
max_iter
|
int
|
Maximum number of iterations. Default (paper): 400. |
None
|
tol
|
float
|
Relative-change tolerance. Default (paper): 10⁻⁵. |
None
|
boundary
|
(periodic, unknown)
|
Periodic blur and differences on the block (default, paper),
or an unobserved margin around it (extension; the default
with |
"periodic"
|
halo
|
int or sequence of int
|
Halo width per spatial axis, at least the PSF size along that
axis. Default: twice the PSF size (not specified in the
paper). A memory setting: does not change |
None
|
block
|
sequence of int or None
|
Core block size per spatial axis (None entries: whole
extent). Default: chosen from the memory budget, the whole
image when it fits. A memory setting: does not change
|
None
|
faithful
|
bool
|
See |
True
|
dtype
|
bool
|
See |
True
|
device
|
bool
|
See |
True
|
layout
|
bool
|
See |
True
|
Chouzenoux
Chouzenoux(psf=None, *, tv=None, hessian=None, upper=None, step=None, max_iter=None, tol=None, halo=None, block=None, on_step_collapse=None, faithful=True, dtype=None, device=None, layout=None)
Bases: _Variational
Deconvolution with the exact Poisson–Gaussian likelihood.
Model (Chouzenoux et al. 2015, Eqs. 2.1–2.7). In electrons, the data are y = Poisson(A x) + N(0, σ²), with A the convolution with the PSF and x ≥ 0. The estimate minimises (Eqs. 2.25–2.28, 3.1)
φ(A x) + ι_C(x) + λ_TV ∑ⱼ ‖(∇x)ⱼ‖₂ + λ_H ∑ⱼ ‖(H x)ⱼ‖₂,
where φ is the exact negative log-likelihood of the observed pixels,
−log ∑ₙ zⁿe^{−z}/n! · e^{−(y − n)²/2σ²}/√(2πσ²) per pixel, continued
by a quadratic for z < 0 (Eq. 2.28; see
PoissonGaussian); C = [0, x₊]
(x₊ = upper, +∞ by default); ∇x is the gradient by forward
differences (isotropic total variation) and (H x)ⱼ packs the second
differences with √2 on the cross terms, so ‖(H x)ⱼ‖₂ is the
Frobenius norm of the Hessian matrix (Section 3.1; the TVH prior of
the paper's experiments). With hessian=0 the prior is the total
variation alone (TV, also the paper's method). The data are used as
they are: the exact likelihood is convex for any y, so negative
values are not clipped.
Solver (Algorithm 1). The primal–dual forward–backward–forward
iteration of primal_dual, with
h = φ(A ·) (∇h = Aᵀ(1 − ξ(A x)), Eqs. 2.8, 2.10), ψ₀ = ι_C
(projection onto C) and one dual variable per regulariser (its prox
is the projection onto the ℓ₂ balls of radius λ). The step is the
largest of Theorem 3.2 (iii), γ = (1 − ε)/δ with
δ = μ + √(∑_r ‖V_r‖²), ‖∇‖² ≤ 4d, ‖H‖² ≤ (4d)² (d dimensions) and the
Lipschitz constant of Eq. (2.13),
μ = ‖A‖² · maxᵢ (1 − e^{−1/σᵢ²}) e^{(2yᵢ − 1)/σᵢ²},
with ‖A‖ = 1 for a unit-sum PSF and the maximum over the pixels of the whole image (so that every block of an image uses the same step).
The step collapses at high counts. μ grows like e^{2 max y/σ²}:
the method is suited to low counts with high read noise. Iterations
advance x by about γ per unit of gradient, so the number needed
grows with (max y + σ²)/γ. When this exceeds 10⁴ (a limit not in
the paper), fit issues a RuntimeWarning (Eq. 2.13) that warns
about early stopping and points to Ikoma,
whose shifted-Poisson approximation of the same noise model has no
such limit; the run then goes ahead as in the paper.
on_step_collapse="raise" turns the warning into a ValueError.
The paper's settings x̄₁ (peak 12, σ² = 9) and x̄₄ (peak 60,
σ² = 36) are below the limit; x̄₂ (peak 30, σ² = 12) and x̄₃ (peak
20, σ² = 9) are above it (about 5·10⁴) and give the warning. Below
the limit too, with the default stopping rule, the result can be
stopped before convergence when the step is small (see
history.extras["change"] and the γ-free "residual").
Series. ξ and φ are evaluated with
poisson_normal_ratio and
poisson_normal_logpdf: in
float64, over a window of n adapted per pixel that leaves out terms
below e⁻⁵⁰ times the largest one. This departs from the paper's
window n* ± Δσ around the Lambert-function estimate n* with a fixed
Δ = 3 (Section 3.4, Eqs. 3.4–3.7); the truncation errors are
negligible, as Theorem 3.2 (iv) requires.
Choices not specified in the paper.
- x₀ is the mean of the image's data (constant), the duals start at 0, and ε = min(10⁻³, ½/(δ + 1)) in the step.
- Stopping: ‖xₖ₊₁ − xₖ‖₂ ≤ 10⁻⁵ ‖xₖ‖₂ or 5000 iterations (the paper
stops "when the difference in norm between two consecutive
iterates becomes small"; its one iteration count for the exact
likelihood is 5500, for x̄₁ with the TVH prior, Figure 3). The
result is p₁ of the last iteration, which lies in C. The relative
change depends on the step; the full forward–backward–forward
residual (‖xₖ − p₁‖² + ∑_r ‖v_r − p₂,r‖²)^½/γ, recorded in
history.extras["residual"], does not. - Boundary: the blur is computed on a grid larger than the block
(the block plus the PSF, rounded up to a fast FFT size), the
likelihood sums over the observed pixels only, and the
differences are periodic on that grid (as for
Ikoma). -
The weights: the paper tunes λ_TV and λ_H per image for the least mean absolute error. The defaults here are
λ_TV = κ_TV / (q₉₉.₉(y) − q₅₀(y)), λ_H = κ_H / (q₉₉.₉(y) − q₅₀(y)),
per image, κ_TV = 0.2 and κ_H = 0.5, with q₉₉.₉(y) the 99.9th
percentile of the data (exact, in the one pass of fit) and
q₅₀(y) their median (from a uniform sample of 8192 pixels, exact
for smaller images), as for HSPIRAL: the
priors ignore a constant, so the signal amplitude above the
background sets their scale, and the 1/scale factor makes the
prior on the normalised image the same at every count (the
likelihood is close to homogeneous, ℓ(s x; s y) ≈ s ℓ(x; y)).
The ratio κ_TV/κ_H = 0.4 is within the flat optimum of a pilot
grid of both weights; with it, the scale was calibrated for the
default stopping rule on simulated images (Gaussian PSF,
σ_b = 1.6, 9 × 9, blurred on a larger field and cropped): cells,
filaments and their mixture; peak 12 (σ² = 9), 30 (σ² = 16) and
60 (σ² = 36) electrons on a smooth background (0 or 1/2 of the
peak at peaks 12 and 60, 0 or 1/3 at peak 30); 32 × 32 (two
seeds) and 64 × 64 (one seed) pixels; the 47 of the 54 cases
below the limit of 10⁴ ((max y + σ²)/γ from 215 to about 10⁴),
against seven scales of the weights from 1/4 to 4 times the
default. There, the default SNR is on average 0.23 dB
below that of the best scale (at most 1.5 dB) and 2.4 to 11 dB
(6.6 dB on average) above that of the data. In two thirds of
these runs the 5000 iterations end before the tolerance is met;
the calibration includes this early stop. Pass tv and hessian
to set the weights; the values used are in tv and hessian
after fit.
Camera calibration (not in the paper, which takes electrons).
With a SensorEstimate given to
fit, y = (data − offset)/gain and σ² = variance/gain² (maps
allowed: the likelihood and μ use the variance of each pixel); with
a ShadingEstimate, the dark
field is subtracted and the data are divided by the flat field (unit
median), as for Ikoma. A sensor estimate
with a positive variance is required: without read noise the model
is Poisson, whose likelihood has no Lipschitz gradient.
Blocks. An image that fits in the memory budget is solved whole;
a larger one is cut into blocks with a halo (default: twice the PSF
size, not specified in the paper), each solved on its own, keeping
its core; the weights and γ are those of the whole image. A
RuntimeWarning says when an image is split. halo and block are
memory settings: they do not change is_faithful.
Cost. Each iteration evaluates the series twice over every pixel, and thousands of iterations are typical: the method is slow on large images and in 3-D (about 16 minutes for 5000 iterations on a 48³ volume on four CPU threads).
Other data in apply. The step is admissible for the data seen
by fit. apply compares the log μ of each block with that of the
fitted image and issues a RuntimeWarning when it is larger: the
step is then no longer admissible; fit on these data.
Paper notation: H the blur (A here); Δʰ, Δᵛ the first and Δʰʰ, Δʰᵛ, Δᵛᵛ the second differences (∇ and H here); μ, γ, ε, δ, ξ, η, λ_TV, λ_H as here; ψ₀ = ι_C.
Not implemented
The paper also compares approximations of the likelihood (its
Table 1: Gaussian, generalised Anscombe transform, exponential,
shifted Poisson, weighted least squares) and a non-local total
variation prior. Only the exact likelihood with the TV and TV +
Hessian priors is implemented; the shifted-Poisson approximation
is Ikoma.
References
- Chouzenoux E, Jezierska A, Pesquet J-C, Talbot H. A convex approach for image restoration with exact Poisson–Gaussian likelihood. SIAM J Imaging Sci 8(4):2662-2682, 2015. doi:10.1137/15M1014395
- Combettes PL, Pesquet J-C. Primal-dual splitting algorithm for solving inclusions with mixtures of composite, Lipschitzian, and parallel-sum type monotone operators. Set-Valued Var Anal 20(2):307-330, 2012. doi:10.1007/s11228-011-0191-y
BibTeX
@article{chouzenoux2015convex,
author = {Chouzenoux, Emilie and Jezierska, Anna and
Pesquet, Jean-Christophe and Talbot, Hugues},
title = {A Convex Approach for Image Restoration with
Exact {Poisson}--{Gaussian} Likelihood},
journal = {SIAM Journal on Imaging Sciences},
volume = {8},
number = {4},
pages = {2662--2682},
year = {2015},
doi = {10.1137/15M1014395}
}
@article{combettes2012primal,
author = {Combettes, Patrick L. and Pesquet, Jean-Christophe},
title = {Primal-Dual Splitting Algorithm for Solving
Inclusions with Mixtures of Composite,
{Lipschitzian}, and Parallel-Sum Type Monotone
Operators},
journal = {Set-Valued and Variational Analysis},
volume = {20},
number = {2},
pages = {307--330},
year = {2012},
doi = {10.1007/s11228-011-0191-y}
}
Attributes:
| Name | Type | Description |
|---|---|---|
tv, hessian |
Tensor
|
Weights λ_TV and λ_H per image |
lipschitz |
Tensor
|
μ per image (Eq. 2.13); inf when it overflows. |
step |
Tensor
|
γ per image. |
peak |
Tensor
|
max y per image. |
robust_peak, median |
Tensor
|
q₉₉.₉(y) and q₅₀(y) per image (used by the default weights); the median is computed from a uniform sample of 8192 pixels (exact for smaller images). |
mean |
Tensor
|
Mean of y per image (x₀). |
Examples:
>>> import torch
>>> from optix.deconv import Chouzenoux
>>> from optix.estimates import SensorEstimate
>>> psf = torch.ones(5, 5)
>>> noise = 3 * torch.randn(32, 32)
>>> data = torch.poisson(torch.full((32, 32), 5.0)) + noise
>>> sensor = SensorEstimate(
... offset=torch.tensor(0.0), gain=torch.tensor(1.0),
... variance=torch.tensor(9.0),
... )
>>> est = Chouzenoux(psf, max_iter=5).fit(data, init=sensor)
>>> est.apply(data).shape
torch.Size([32, 32])
Configure the deconvolution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
psf
|
Tensor
|
Point spread function, |
None
|
tv
|
float
|
Weight λ_TV ≥ 0 of the total variation (0 removes it). Default: κ_TV / (q₉₉.₉(y) − q₅₀(y)) per image (see above; not in the paper). |
None
|
hessian
|
float
|
Weight λ_H ≥ 0 of the Frobenius norm of the Hessian (0 removes it: the TV prior). Default: κ_H / (q₉₉.₉(y) − q₅₀(y)) per image (not in the paper). |
None
|
upper
|
float
|
Upper bound x₊ > 0 of C = [0, x₊], in electrons. Default: none, C = [0, +∞) (the paper's choice when x₊ is unknown). |
None
|
step
|
float
|
Step γ > 0. Default (paper): the largest step of Theorem 3.2
(see above). A given step skips the high-count check and the
check of |
None
|
max_iter
|
int
|
Maximum number of iterations. Default: 5000 (not in the
paper, whose one count for the exact likelihood is 5500).
Does not change |
None
|
tol
|
float
|
Relative-change tolerance (0 runs |
None
|
halo
|
int or sequence of int
|
Halo width per spatial axis, at least the PSF size along that
axis. Default: twice the PSF size (not specified in the
paper). A memory setting: does not change |
None
|
block
|
sequence of int or None
|
Core block size per spatial axis (None entries: whole
extent). Default: chosen from the memory budget, the whole
image when it fits. A memory setting: does not change
|
None
|
on_step_collapse
|
(warn, 'raise')
|
What |
"warn"
|
faithful
|
bool
|
See |
True
|
dtype
|
bool
|
See |
True
|
device
|
bool
|
See |
True
|
layout
|
bool
|
See |
True
|
Shift-variant PSF models
Deconvolution with a known point spread function.
Richardson–Lucy for Poisson counts, its acceleration by Biggs & Andrews (1997), its extension by Snyder et al. (1993) to CCD data (flat field, background counts, read noise) and its total-variation regularisation by Dey et al. (2006); multiview deconvolution of registered views by Preibisch et al. (2014); the linear Wiener and Tikhonov filters; the regularised shifted-Poisson deconvolution of Ikoma et al. (2018) and the Hessian Schatten-norm Poisson deconvolution of Lefkimmiatis & Unser (2013), both solved by ADMM, and the exact Poisson–Gaussian likelihood deconvolution of Chouzenoux et al. (2015), solved by primal–dual splitting. Spatially variant blur: the PSF models of Nagy & O'Leary (1998) and Denis et al. (2015), usable as the PSF of the Richardson–Lucy family, and the preconditioned conjugate-gradient restoration of Nagy & O'Leary.
Building blocks (FFT convolution with padding, the shift-variant
operator, the Richardson–Lucy update, the Biggs–Andrews acceleration
parameter, the back projectors) are in optix.deconv.utils.
NagyOLearyPSF
NagyOLearyPSF(psf, centres, *, interpolation='constant', normalize=True)
Bases: ShiftVariantPSF
Shift-variant blur of Nagy & O'Leary (1998): convolve, then weight.
PSFs kᵢ are given at p points sᵢ of a rectangular grid. The blur is
K = D₁ K₁ + D₂ K₂ + ⋯ + Dₚ Kₚ (Eq. 2.1),
Kᵢ the convolution with kᵢ and Dᵢ a non-negative diagonal matrix
with ∑ Dᵢ = I, applied to the blurred images: each pixel of the
image is a weighted sum of the images blurred by each PSF. With
interpolation="constant" (§3.2.1), Dᵢ is the indicator of the
region of PSF i: the image is partitioned into rectangles, one per
PSF, with boundaries half-way between neighbouring centres. With
interpolation="linear" (§3.2.2), the weights interpolate linearly
between the PSF centres on a triangulation of the grid: each
rectangle of four neighbouring centres is split into two triangles
along the diagonal from its first corner (lowest index along every
axis) to the opposite one; in 3-D, the Kuhn triangulation of each
box into six tetrahedra. The paper only asks for a triangulation;
its Fig. 3.2 draws the other diagonal, and either is valid. Beyond
the outermost centres the weights are constant.
The paper recommends the piecewise-constant model where linear
interpolation brings no gain (§5).
Denis et al. (2015) show that this model is not the blur of an
interpolated PSF: see DenisPSF.
References
- Nagy JG, O'Leary DP. Restoring images degraded by spatially variant blur. SIAM J Sci Comput 19(4):1063-1082, 1998. doi:10.1137/S106482759528507X
BibTeX
@article{nagy1998restoring,
author = {Nagy, James G. and O'Leary, Dianne P.},
title = {Restoring Images Degraded by Spatially Variant
Blur},
journal = {SIAM Journal on Scientific Computing},
volume = {19},
number = {4},
pages = {1063--1082},
year = {1998},
doi = {10.1137/S106482759528507X}
}
Examples:
>>> import torch
>>> from optix.deconv import NagyOLearyPSF
>>> psf = torch.ones(2, 2, 5, 5) # 2 × 2 grid of 5 × 5 PSFs
>>> model = NagyOLearyPSF(psf, [[16, 48], [16, 48]])
>>> model.operator((0, 0), (64, 64)).shape
(64, 64)
Set up the model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
psf
|
Tensor
|
PSFs |
required |
centres
|
sequence of 1-D tensors
|
Position (in pixels, along each spatial axis) of the grid
nodes: PSF |
required |
interpolation
|
(constant, linear)
|
Weights Dᵢ: region indicators (§3.2.1) or piecewise-linear
interpolation on a triangulation (§3.2.2). Default:
|
"constant"
|
normalize
|
bool
|
Divide each PSF by its sum (unit-sum PSFs, as in §5). |
True
|
regions
regions(coords)
Piecewise-constant regions met by an open grid of positions.
Returns, per region, the flat index of its PSF and the slices
(into coords) of its intersection with the positions.
DenisPSF
DenisPSF(psf, centres, *, model='interpolation', rank=None, psf_model=None, extent=None, n_alt=10, normalize=True)
Bases: ShiftVariantPSF
Shift-variant blur of Denis et al. (2015): weight, then convolve.
The un-shifted PSF at each object location j (the column K⋅ⱼ of the PSF matrix K) is approximated by a few terms, K ≈ ∑ₚ cₚ wₚᵀ, which gives the blur as a sum of convolutions of weighted objects,
H ≈ ∑ₚ conv(cₚ) · diag(wₚ) (Eq. 14).
Three approximations of the paper are available (model):
"interpolation"(§2.3, Eqs. 21–22): cₚ = kₚ are the PSFs sampled on a grid and wₚ = φₚ the weights of their bilinear (trilinear in 3-D) interpolation, so the PSF at every location is the linear interpolation of the sampled PSFs. It preserves the positivity, the normalisation and the symmetries of the PSFs (§3.2)."modes"(§2.4; the practical scheme of Flicker & Rigaut 2005): PSF modes cₚ = uₚ, the firstrankleft singular vectors of the matrix of the G sampled PSFs (L × G), with coefficients σₚ vₚ at the nodes, interpolated between nodes with the bilinear weights φ. This departs from Eqs. 26–28, which take the SVD of K, the PSFs of every pixel (L × M), with no interpolation. With all modes it equals"interpolation". The truncation is the best rank-rankapproximation of the samples only, with error ∑_{p > rank} σₚ² on them (Eckart–Young), not of the PSFs over the whole field."optimal"(§2.5, Eqs. 29–38): the optimal local approximation proposed by the paper. The weights keep the support of the bilinear weights, and both the kernels and the weights minimise ‖K − C Wᵀ‖²_F, the error on the PSFs of every pixel of the image, by alternating C* = K W (WᵀW)⁻¹ (Eq. 35) and, per pixel, ωⱼ = (C′ⱼᵀC′ⱼ)⁻¹C′ⱼᵀK⋅ⱼ over the 2ᵈ nodes of its grid cell (Eq. 37; C′ⱼ is the same for every pixel of a cell, so its pseudo-inverse is computed once per cell), starting from the interpolation model;n_alt= 10 alternations, as in the paper. It needs apsf_modelthat gives the PSF at any position, and the imageextent. As in §2.5.2, the kernels and the weights ω of every pixel are computed once, when the model is built, and stored (2ᵈ values per pixel); operators then only slice them, and the model can be saved withoutpsf_model. The fit evaluatespsf_modelat every pixel n_alt + 1 times, in batches sized from the memory budget, at a cost of about (n_alt + 1)·M·L·2ᵈ operations (M pixels, L the PSF size): fine in 2-D, heavy for large volumes with large 3-D PSFs.
The paper recommends PSF interpolation over the convolve-then-weight
model of Nagy & O'Leary
(NagyOLearyPSF) and proposes the
optimal local approximation for the best accuracy at the same cost.
Choices not specified in the paper
- Outside the grid of centres the weights are constant (clamped).
- With
"modes", the singular value decomposition is that of the sampled PSFs (one column per grid node) and the mode coefficients are interpolated bilinearly between nodes; the defaultrankkeeps all modes. - With
"optimal", positions outside the image are clamped to it before evaluatingpsf_model, and least-squares problems are solved with the pseudo-inverse (minimum-norm solution) so that identical neighbouring PSFs are allowed. - With
"optimal", all 2ᵈ nodes of a pixel's (clamped) grid cell carry a weight, the paper's "weights of a cell". The support constraint of Eq. 31, supp(wₚ) ⊂ supp(φₚ), is therefore loosened where φₚ vanishes on a cell node: beyond the outermost centres, where the clamped φ is non-zero only on the edge nodes, and exactly on grid lines.
References
- Denis L, Thiébaut É, Soulez F, Becker J-M, Mourya R. Fast approximations of shift-variant blur. Int J Comput Vis 115(3):253-278, 2015. doi:10.1007/s11263-015-0817-x
BibTeX
@article{denis2015fast,
author = {Denis, Lo{\"\i}c and Thi{\'e}baut, Eric and
Soulez, Ferr{\'e}ol and Becker, Jean-Marie and
Mourya, Rahul},
title = {Fast Approximations of Shift-Variant Blur},
journal = {International Journal of Computer Vision},
volume = {115},
number = {3},
pages = {253--278},
year = {2015},
doi = {10.1007/s11263-015-0817-x}
}
Attributes:
| Name | Type | Description |
|---|---|---|
kernels |
Tensor
|
cₚ, |
singular_values |
Tensor or None
|
σ of the sampled PSFs ( |
omega |
Tensor
|
|
Examples:
>>> import torch
>>> from optix.deconv import DenisPSF
>>> psf = torch.ones(2, 2, 5, 5)
>>> model = DenisPSF(psf, [[16, 48], [16, 48]])
>>> model.operator((0, 0), (64, 64)).shape
(64, 64)
Set up the model (and fit it, for model="optimal").
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
psf
|
Tensor
|
Sampled PSFs |
required |
centres
|
sequence of 1-D tensors
|
Position (in pixels, per spatial axis) of the grid nodes. |
required |
model
|
(interpolation, modes, optimal)
|
Approximation (see above). Default: |
"interpolation"
|
rank
|
int
|
Number of PSF modes ( |
None
|
psf_model
|
callable
|
|
None
|
extent
|
sequence of int
|
|
None
|
n_alt
|
int
|
|
10
|
normalize
|
bool
|
Divide each PSF (sampled, and from |
True
|
Transforms
Deconvolution with a known point spread function.
Richardson–Lucy for Poisson counts, its acceleration by Biggs & Andrews (1997), its extension by Snyder et al. (1993) to CCD data (flat field, background counts, read noise) and its total-variation regularisation by Dey et al. (2006); multiview deconvolution of registered views by Preibisch et al. (2014); the linear Wiener and Tikhonov filters; the regularised shifted-Poisson deconvolution of Ikoma et al. (2018) and the Hessian Schatten-norm Poisson deconvolution of Lefkimmiatis & Unser (2013), both solved by ADMM, and the exact Poisson–Gaussian likelihood deconvolution of Chouzenoux et al. (2015), solved by primal–dual splitting. Spatially variant blur: the PSF models of Nagy & O'Leary (1998) and Denis et al. (2015), usable as the PSF of the Richardson–Lucy family, and the preconditioned conjugate-gradient restoration of Nagy & O'Leary.
Building blocks (FFT convolution with padding, the shift-variant
operator, the Richardson–Lucy update, the Biggs–Andrews acceleration
parameter, the back projectors) are in optix.deconv.utils.
richardson_lucy
richardson_lucy(data, psf, *, out=None, sensor=None, layout=None, **options)
Richardson–Lucy deconvolution of data with a known PSF.
Shortcut for RichardsonLucy(psf, **options).fit(data,
init=sensor).apply(data, out); see
RichardsonLucy for the model, the
defaults and the extensions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
array - like or Labeled
|
Images; |
required |
psf
|
Tensor or ShiftVariantPSF
|
Point spread function, centred at index |
required |
out
|
writable array-like
|
Output (tensor, numpy, zarr, ...). Default: a new tensor. |
None
|
sensor
|
SensorEstimate
|
Camera model; the data are converted to electrons. |
None
|
layout
|
Layout
|
Axis roles. |
None
|
**options
|
object
|
Options of |
{}
|
Returns:
| Type | Description |
|---|---|
writable array-like
|
|
richardson_lucy_tv
richardson_lucy_tv(data, psf, *, out=None, sensor=None, layout=None, **options)
Richardson–Lucy deconvolution with total-variation regularisation.
Shortcut for RichardsonLucyTV(psf, **options).fit(data,
init=sensor).apply(data, out); see
RichardsonLucyTV for the model,
the defaults and the extensions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
array - like or Labeled
|
Images; |
required |
psf
|
Tensor
|
Point spread function, centred at index |
required |
out
|
writable array-like
|
Output (tensor, numpy, zarr, ...). Default: a new tensor. |
None
|
sensor
|
SensorEstimate
|
Camera model; the data are converted to electrons. |
None
|
layout
|
Layout
|
Axis roles. |
None
|
**options
|
object
|
Options of |
{}
|
Returns:
| Type | Description |
|---|---|
writable array-like
|
|
wiener_butterworth
wiener_butterworth(data, psf, *, out=None, sensor=None, layout=None, **options)
Richardson–Lucy deconvolution with a Wiener–Butterworth back projector.
Shortcut for WienerButterworth(psf, **options).fit(data,
init=sensor).apply(data, out); see
WienerButterworth for the model,
the defaults and the extensions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
array - like or Labeled
|
Images; |
required |
psf
|
Tensor
|
Point spread function, centred at index |
required |
out
|
writable array-like
|
Output (tensor, numpy, zarr, ...). Default: a new tensor. |
None
|
sensor
|
SensorEstimate
|
Camera model; the data are converted to electrons. |
None
|
layout
|
Layout
|
Axis roles. |
None
|
**options
|
object
|
Options of |
{}
|
Returns:
| Type | Description |
|---|---|
writable array-like
|
|
biggs_andrews
biggs_andrews(data, psf, *, out=None, sensor=None, layout=None, **options)
Accelerated Richardson–Lucy deconvolution of data.
Shortcut for BiggsAndrews(psf, **options).fit(data,
init=sensor).apply(data, out); see
BiggsAndrews for the acceleration and
RichardsonLucy for the model, the
defaults and the extensions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
array - like or Labeled
|
Images; |
required |
psf
|
Tensor or ShiftVariantPSF
|
Point spread function, centred at index |
required |
out
|
writable array-like
|
Output (tensor, numpy, zarr, ...). Default: a new tensor. |
None
|
sensor
|
SensorEstimate
|
Camera model; the data are converted to electrons. |
None
|
layout
|
Layout
|
Axis roles. |
None
|
**options
|
object
|
Options of |
{}
|
Returns:
| Type | Description |
|---|---|
writable array-like
|
|
nagy_oleary
nagy_oleary(data, psf, centres, *, out=None, layout=None, **options)
Restoration of data blurred by a spatially variant PSF.
Shortcut for NagyOLeary(psf, centres, **options).fit(data)
.apply(data, out); see NagyOLeary for
the model and the defaults.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
array - like or Labeled
|
Images; |
required |
psf
|
Tensor
|
PSFs |
required |
centres
|
sequence of 1-D tensors
|
Position of the grid nodes along each spatial axis. |
required |
out
|
writable array-like
|
Output. Default: a new tensor. |
None
|
layout
|
Layout
|
Axis roles. |
None
|
**options
|
object
|
Options of |
{}
|
Returns:
| Type | Description |
|---|---|
writable array-like
|
|
multiview_rl
multiview_rl(data, psfs, *, out=None, weights=None, layout=None, **options)
Multiview deconvolution of registered views.
The method of Preibisch et al. 2014.
Shortcut for MultiviewRL(psfs, weights=weights, **options).fit(data)
.apply(data, out); see MultiviewRL for
the model, the variants and the defaults.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
sequence of array-like or Labeled
|
Views on the common grid, one per PSF, all of the same shape. |
required |
psfs
|
sequence of Tensor
|
PSF of each view, centred at index |
required |
out
|
writable array-like
|
Output (tensor, numpy, zarr, ...). Default: a new tensor. |
None
|
weights
|
sequence of array-like
|
Per-view weights of the sequential update. |
None
|
layout
|
Layout
|
Axis roles, shared by the views. |
None
|
**options
|
object
|
Options of |
{}
|
Returns:
| Type | Description |
|---|---|
writable array-like
|
|
wiener
wiener(data, psf, *, nsr=None, out=None, sensor=None, layout=None, **options)
Wiener deconvolution of data with a known PSF.
Shortcut for Wiener(psf, nsr=nsr, **options).fit(data,
init=sensor).apply(data, out); see Wiener
for the filter, F̂ = H* Y / (|H|² + K), and its options.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
array - like or Labeled
|
Images; |
required |
psf
|
Tensor
|
Point spread function, centred at index |
required |
nsr
|
float or callable
|
Noise-to-signal ratio K, constant or K(ν). |
None
|
out
|
writable array-like
|
Output (tensor, numpy, zarr, ...). Default: a new tensor. |
None
|
sensor
|
SensorEstimate
|
Camera model; the data are converted to electrons. |
None
|
layout
|
Layout
|
Axis roles. |
None
|
**options
|
object
|
Options of |
{}
|
Returns:
| Type | Description |
|---|---|
writable array-like
|
|
tikhonov
tikhonov(data, psf, *, lam=None, operator=None, out=None, sensor=None, layout=None, **options)
Tikhonov-regularised deconvolution of data with a known PSF.
Shortcut for Tikhonov(psf, lam=lam, operator=operator,
**options).fit(data, init=sensor).apply(data, out); see
Tikhonov for the filter,
F̂ = H* Y / (|H|² + λ |L|²), and its options.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
array - like or Labeled
|
Images; |
required |
psf
|
Tensor
|
Point spread function, centred at index |
required |
lam
|
float or gcv
|
Regularisation weight λ. |
None
|
operator
|
(identity, laplacian)
|
Regularisation operator L. |
"identity"
|
out
|
writable array-like
|
Output (tensor, numpy, zarr, ...). Default: a new tensor. |
None
|
sensor
|
SensorEstimate
|
Camera model; the data are converted to electrons. |
None
|
layout
|
Layout
|
Axis roles. |
None
|
**options
|
object
|
Options of |
{}
|
Returns:
| Type | Description |
|---|---|
writable array-like
|
|
ikoma
ikoma(data, psf, *, out=None, sensor=None, shading=None, layout=None, **options)
Deconvolution of Ikoma et al. (2018) of data with a known PSF.
Shortcut for Ikoma(psf, **options).fit(data, init=[sensor,
shading]).apply(data, out); see Ikoma for
the model, the defaults and the extensions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
array - like or Labeled
|
Images; |
required |
psf
|
Tensor
|
Point spread function, centred at index |
required |
out
|
writable array-like
|
Output. Default: a new tensor. |
None
|
sensor
|
SensorEstimate
|
Camera model (offset, gain, read-noise variance). |
None
|
shading
|
ShadingEstimate
|
Dark and flat fields. |
None
|
layout
|
Layout
|
Axis roles. |
None
|
**options
|
object
|
Options of |
{}
|
Returns:
| Type | Description |
|---|---|
writable array-like
|
|
hspiral
hspiral(data, psf, *, out=None, sensor=None, shading=None, layout=None, **options)
HSPIRAL deconvolution of Lefkimmiatis & Unser (2013) of data.
Shortcut for HSPIRAL(psf, **options).fit(data, init=[sensor,
shading]).apply(data, out); see HSPIRAL
for the model, the defaults and the extensions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
array - like or Labeled
|
Images; |
required |
psf
|
Tensor
|
Point spread function, centred at index |
required |
out
|
writable array-like
|
Output. Default: a new tensor. |
None
|
sensor
|
SensorEstimate
|
Camera offset and gain (the read noise is not used). |
None
|
shading
|
ShadingEstimate
|
Dark and flat fields. |
None
|
layout
|
Layout
|
Axis roles. |
None
|
**options
|
object
|
Options of |
{}
|
Returns:
| Type | Description |
|---|---|
writable array-like
|
|
chouzenoux
chouzenoux(data, psf, *, out=None, sensor=None, shading=None, layout=None, **options)
Deconvolution of Chouzenoux et al. (2015) of data.
Shortcut for Chouzenoux(psf, **options).fit(data, init=[sensor,
shading]).apply(data, out); see
Chouzenoux for the model and the
defaults.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
array - like or Labeled
|
Images; |
required |
psf
|
Tensor
|
Point spread function, centred at index |
required |
out
|
writable array-like
|
Output. Default: a new tensor. |
None
|
sensor
|
SensorEstimate
|
Camera model (offset, gain and read-noise variance, required). |
None
|
shading
|
ShadingEstimate
|
Dark and flat fields. |
None
|
layout
|
Layout
|
Axis roles. |
None
|
**options
|
object
|
Options of |
{}
|
Returns:
| Type | Description |
|---|---|
writable array-like
|
|
Utilities
No stability promise
optix.deconv.utils holds building blocks of the estimators above; they may change without notice.
Building blocks of the deconvolution estimators.
Semi-public: these may change without notice.
PaddedConvolution
PaddedConvolution(psf, shape, *, dtype=None, device=None)
Blur operator H of a block, by FFT on a padded grid.
The observed block y has shape L (the trailing psf.ndim dims). The
object f lives on a larger grid of shape N ≥ L + K − 1 (K the PSF
shape), rounded up to 2ᵃ3ᵇ5ᶜ along each dim, so that light from
outside the block that the PSF spreads into it is modelled. The
operator is
(H f)ᵢ = ∑ⱼ S(i − j) fⱼ, i in the block,
computed as a circular convolution on the N grid and cropped to the block. With N ≥ L + K − 1 the wrap-around never reaches the block, so the circular and linear models agree. Object index j and data index i refer to the same location for j < L; the extra object pixels j ≥ L hold the margin around the block (periodically, on both sides).
The PSF is centred at index K // 2 along each dim.
Attributes:
| Name | Type | Description |
|---|---|---|
shape |
tuple of int
|
Block shape L. |
grid |
tuple of int
|
Padded object grid N. |
norm |
Tensor
|
Hᵀ1, the adjoint applied to a block of ones, on the N grid. It equals ∑S inside the block, away from its edges, and decays to 0 in the margin. |
Precompute the transfer function and the normaliser.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
psf
|
Tensor
|
Point spread function, |
required |
shape
|
sequence of int
|
Block shape L, with |
required |
dtype
|
optional
|
Working backend (default: those of |
None
|
device
|
optional
|
Working backend (default: those of |
None
|
pad
pad(x)
Zero-pad a block (..., *L) to the grid (..., *N).
crop
crop(x)
Restrict an object (..., *N) to the block (..., *L).
forward
forward(f)
H f: object (..., *N) to blurred block (..., *L).
adjoint
adjoint(r)
Hᵀ r: block (..., *L) to object (..., *N) (correlation).
ShiftVariantConvolution
ShiftVariantConvolution(kernels, weights, shape, *, order='input', dtype=None, device=None)
Shift-variant blur operator H of a block, a sum of convolutions.
The blur is a sum of T convolutions with kernels kₜ and spatial
weights wₜ, applied either before the convolutions (on the object,
order="input") or after them (on the blurred image,
order="output"):
input: H f = ∑ₜ kₜ ∗ (wₜ ⊙ f),
output: H f = ∑ₜ wₜ ⊙ (kₜ ∗ f).
As in PaddedConvolution,
the object lives on a padded grid of shape N ≥ L + K − 1 (rounded up
to 2ᵃ3ᵇ5ᶜ), the convolutions are circular on that grid and the result
is cropped to the block, so the circular and linear models agree on
the block. The adjoint is the exact transpose,
input: Hᵀ r = ∑ₜ wₜ ⊙ (kₜ ⋆ r),
output: Hᵀ r = ∑ₜ kₜ ⋆ (wₜ ⊙ r),
with ⋆ the correlation (multiplication by the conjugate transfer
function). With a single term and w = 1 it is PaddedConvolution.
Kernels are centred at index K // 2.
Attributes:
| Name | Type | Description |
|---|---|---|
shape |
tuple of int
|
Block shape L. |
grid |
tuple of int
|
Padded object grid N. |
order |
str
|
|
weights |
Tensor
|
|
norm |
Tensor
|
Hᵀ1 on the object grid. |
Precompute the transfer functions and the normaliser.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
kernels
|
Tensor
|
|
required |
weights
|
Tensor or callable
|
|
required |
shape
|
sequence of int
|
Block shape L. |
required |
order
|
(input, output)
|
Where the weights are applied. |
"input"
|
dtype
|
optional
|
Working backend (default: those of |
None
|
device
|
optional
|
Working backend (default: those of |
None
|
pad
pad(x)
Zero-pad a block (..., *L) to the grid (..., *N).
crop
crop(x)
Restrict an object (..., *N) to the block (..., *L).
forward
forward(f)
H f: object (..., *N) to blurred block (..., *L).
adjoint
adjoint(r)
Hᵀ r: block (..., *L) to object (..., *N).
ShiftVariantPSF
A shift-variant PSF model: builds the blur operator of any block.
Base class of the models
NagyOLearyPSF and
DenisPSF. A model can be given as the
psf of RichardsonLucy,
BiggsAndrews and
Snyder. The weights of each block are
evaluated at the global positions of its pixels, so the operator of
a block is the restriction of the whole-image operator, whatever the
blocking.
Attributes:
| Name | Type | Description |
|---|---|---|
ndim |
int
|
Number of spatial dims d. |
shape |
tuple of int
|
Kernel shape K (the support of every PSF of the model). |
order |
str
|
|
kernels |
Tensor
|
Kernels of the terms, |
terms
terms(coords)
Kernels (T, *K) and weights (T, *n) at global positions.
n_terms
n_terms(extent)
Upper bound on the number of terms T of any block of an image.
It counts the nodes whose weights are non-zero somewhere on the
image of shape extent or within one kernel size of it (the
object grid of a block): at most the number of PSFs on the grid,
or the number of kernels for models with full-field weights.
Blocks, and the memory they take, are sized from it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
extent
|
sequence of int
|
Image shape. |
required |
Returns:
| Type | Description |
|---|---|
int
|
|
operator
operator(origin, shape)
Blur operator of the block of shape shape at origin.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
origin
|
sequence of int
|
Global position of the first block pixel, per spatial axis. |
required |
shape
|
sequence of int
|
Block shape L. |
required |
Returns:
| Type | Description |
|---|---|
ShiftVariantConvolution
|
|
to
to(**backend)
A copy with kernels on another dtype / device.
RegionPreconditioner
RegionPreconditioner(regions, *, tau=0.0)
Block-diagonal circulant preconditioner Cτ of Nagy & O'Leary (§4).
On each region i of the piecewise-constant partition, Cᵢ is the
optimal circulant approximation
(optimal_circulant) of the
blur by PSF i restricted to the region; C is block diagonal with
blocks Cᵢ, and Cτ replaces the eigenvalues of magnitude below τ by 1
(Hanke, Nagy & Plemmons). Eigenvalues that vanish to round-off
(below ε·max |λ|, ε the machine epsilon) are also replaced by 1, so
that τ = 0 is well defined. Object pixels outside the regions (the
margin of the padded grid) are left unchanged.
Attributes:
| Name | Type | Description |
|---|---|---|
boxes |
list of tuple of slice
|
Region boxes on the object grid. |
eigenvalues |
list of Tensor
|
Eigenvalues of Cτ per box ( |
Precompute the eigenvalues.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
regions
|
list of (Tensor, tuple of slice)
|
Kernel and box of each region, the boxes on the object grid. |
required |
tau
|
float
|
Truncation level τ ≥ 0. |
0.0
|
apply
apply(x)
Cτ⁻¹ x.
transpose
transpose(x)
Cτ⁻ᵀ x.
BackProjection
BackProjection(kernel, op)
Unmatched back projector B of a block: convolution with a kernel b.
For a residual r on the block (shape L), B r is the linear convolution
of r with b, on the padded object grid N of a
PaddedConvolution:
(B r)ⱼ = ∑ᵢ b(j − i) rᵢ.
With b the flipped PSF, B = Hᵀ. A kernel no larger than the PSF of the operator fits on its grid without wrap-around.
On the margin of the object domain (the object pixels outside the block), B is replaced by Hᵀ: the data barely constrain these pixels, and a kernel with negative lobes makes the correction B r / B1 a weighted mean of r with weights of both signs, which does not pull them back. Hᵀ is also used inside the block where the negative weights nearly cancel the positive ones, B1 < ½ ∑ᵢ|b(j − i)| / ∑|b| (near its edges, for strongly oscillating kernels).
Attributes:
| Name | Type | Description |
|---|---|---|
usable |
Tensor
|
Object pixels, on the grid N, where B is used (elsewhere Hᵀ). |
Precompute the transfer function of b on the grid of op.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
kernel
|
Tensor
|
Kernel b, |
required |
op
|
PaddedConvolution
|
Blur operator H of the block, which sets the grids. |
required |
__call__
__call__(r)
B r: block (..., *L) to object (..., *N).
Multiview
Multiview(ops, kernels=None, *, update='sequential', weights=None)
Blur and back projection of several registered views of one block.
The views y₁, …, y_N of the block (shape L each) are images of one
object f on the padded grid N of their blur operators Hᵥ (one
PaddedConvolution per view,
all on the same grid). As an operator on f this is the stacked blur
H = [H₁; …; H_N], f ↦ (Hᵥ f)ᵥ, of shape (N, *L), with Hᵀ r =
∑ᵥ Hᵥᵀ rᵥ: it gives rl_block the
blurred estimates for its χ² test and the support of the object. The
multiview update itself is step,
passed to rl_block as its step hook.
The correction of view v, from its back projector Bᵥ (Hᵥᵀ, or the
convolution with a compound kernel, see
compound_kernels), is
cᵥ = Bᵥ[yᵥ / (Hᵥ f + b)] / Bᵥ1,
set to 1 on object pixels that view v does not reach (no update).
Margin. The object domain is the block padded by the PSF support;
its margin (object pixels outside the block) is observed by no view
directly, only through the tails of the PSFs. There the back
projector of every view is Hᵥᵀ, whatever the kernel
(BackProjection uses the
compound kernel inside the block only; the compound kernels are
narrower and would leave part of the margin without an update), so
Bᵥ1 = Hᵥᵀ1 there. Not specified in the paper.
Edge damping. On the margin the sequential and multiplicative updates apply view v's correction with the weight
ρᵥ = Hᵥᵀ1 / maxᵤ Hᵤᵀ1 ∈ [0, 1],
its reach relative to the view that sees the pixel best, as f ← f · (1 − ρᵥ + ρᵥ cᵥ). Ordered-subset updates assume subsets of equal sensitivity Hᵥᵀ1; away from the image border every view has sensitivity 1, but on the margin the reaches of the views differ by orders of magnitude, and a view that reaches a pixel only through the far tail of its PSF would otherwise apply a full correction drawn from almost no data (in the extreme, a ratio of two round-off-sized numbers). Scaling each view's step by ρᵥ ≤ 1 restores the balance between the views. It changes neither the fixed points (1 − ρᵥ + ρᵥ cᵥ = 1 exactly where cᵥ = 1) nor positivity. Without it the noise-free data misfit of the sequential update is not monotone and stalls an order of magnitude higher, in double precision too, and float32 and float64 results differ visibly near the image border. Not specified in the paper.
Inside the block ρᵥ = 1, so the update rule there is unchanged; the result next to the image border still differs from the undamped one, since the margin feeds the border pixels through the blur. With one view there is no damping (ρ = 1 everywhere) and the iteration is exactly single-view Richardson–Lucy.
Weights (sequential update). Given weights wᵥ on the block are used inside it; on the margin they are carried over as
wᵥ = ρᵥ · clamp(Bᵥ[wᵥ] / Bᵥ1, 0, 1),
the weights of the block pixels that view v back-projects onto each margin pixel, so that a view with weight 0 at an image border does not update the margin beyond it (zero is absorbing for a multiplicative update, so a correction of 0 there could not be undone by the other views). Not specified in the paper. The weights only gate the update: within a PSF half-width of the edge of a view's coverage, its pixels outside the coverage still enter cᵥ as observed values (zeros if the view has no data there), so the fall-off of the weights should be at least as wide as the PSF.
Attributes:
| Name | Type | Description |
|---|---|---|
ops |
list of PaddedConvolution
|
Blur operator Hᵥ of each view. |
backs |
list of BackProjection or None
|
Back projector Bᵥ of each view (None: Hᵥᵀ). |
update |
str
|
|
weights |
Tensor or None
|
Weights wᵥ ∈ [0, 1] of the views on the object grid, |
shape |
tuple of int
|
|
grid |
tuple of int
|
Object grid N. |
norm |
Tensor
|
Hᵀ1 = ∑ᵥ Hᵥᵀ1 on the object grid. |
Set up the per-view operators of a block.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ops
|
sequence of PaddedConvolution
|
Blur operator Hᵥ of each view, all on the same block shape and grid (PSFs of the same shape). |
required |
kernels
|
sequence of Tensor or None
|
Back-projection kernel bᵥ of each view (no larger than the
PSFs of |
None
|
update
|
(sequential, multiplicative, additive)
|
How the corrections of the views are combined (see
|
"sequential"
|
weights
|
Tensor
|
Weights wᵥ ∈ [0, 1] of each view on the block, |
None
|
weighted
weighted(weights)
A copy with other per-view weights (operators shared).
forward
forward(f)
(Hᵥ f)ᵥ: object (*N) to views (N_views, *L).
adjoint
adjoint(r)
∑ᵥ Hᵥᵀ rᵥ: views (N_views, *L) to object (*N).
pad
pad(x)
Zero-pad a block (..., *L) to the grid (..., *N).
crop
crop(x)
Restrict an object (..., *N) to the block (..., *L).
correction
correction(v, f, data, *, background=0.0, mu=None)
Correction cᵥ = Bᵥ[yᵥ / (Hᵥ f + b)] / Bᵥ1 of view v.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
v
|
int
|
View index. |
required |
f
|
Tensor
|
Current estimate on the object grid. |
required |
data
|
Tensor
|
View yᵥ on the block, |
required |
background
|
Tensor or float
|
Background b of the view. |
0.0
|
mu
|
Tensor
|
Hᵥ f + b if already computed. |
None
|
Returns:
| Type | Description |
|---|---|
Tensor
|
cᵥ on the object grid, 1 where view v does not reach. |
step
step(f, data, op=None, *, inv_norm=None, background=0.0, damping=1.0, mu=None, flat=None, back=None, penalty=None)
One multiview iteration: every view contributes once.
With cᵥ the correction of view v and ε = damping,
"sequential"(Eqs. 104–107 and 109–112, Eq. 3 of the Online Methods with weights): for v = 1, …, N in turn, f ← f · (1 − εwᵥ + εwᵥ cᵥ), cᵥ evaluated at the current f;"multiplicative"(Eqs. 36–37, with the |V|-th root of Eqs. 46–47): f ← f · (1 − ε + ε (∏ᵥ c̃ᵥ)^{1/N}), with c̃ᵥ = 1 − wᵥ + wᵥ cᵥ (wᵥ = 1 inside the block);"additive"(maximum-likelihood EM of the stacked views, Shepp & Vardi 1982): f ← f · (1 − ε + ε ∑ᵥ Bᵥ[yᵥ / Hᵥ f] / ∑ᵥ Bᵥ1),
and negative values (from FFT round-off) are set to 0. With one
view, all three are rl_step.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
f
|
Tensor
|
Current estimate on the object grid. |
required |
data
|
Tensor
|
Views on the block, |
required |
op
|
object
|
Ignored (the hook passes this |
None
|
inv_norm
|
Tensor
|
Ignored: each view has its own normaliser Bᵥ1. |
None
|
background
|
Tensor or float
|
Background b, broadcast to the views |
0.0
|
damping
|
float
|
Fraction ε ∈ (0, 1] of the correction applied. |
1.0
|
mu
|
Tensor
|
(Hᵥ f + b)ᵥ at |
None
|
flat
|
Tensor | None
|
Not supported (must be None). |
None
|
back
|
Tensor | None
|
Not supported (must be None). |
None
|
penalty
|
callable
|
Not implemented (must be None): a one-step-late penalty such as total variation would divide the combined correction, which the sequential update has no single place for. |
None
|
Returns:
| Type | Description |
|---|---|
Tensor
|
Updated estimate, non-negative. |
interpolation_weights
interpolation_weights(centres, coords, kind)
Interpolation weights of a rectilinear grid of nodes.
The nodes sit at the outer product of centres (one increasing 1-D
tensor per axis). A position x falls in the grid cell
[cᵢ, cᵢ₊₁] along each axis, with local coordinate
tₐ = (xₐ − cᵢ)/(cᵢ₊₁ − cᵢ); positions outside the grid are clamped
to it (constant extrapolation). With δ ∈ {0, 1}ᵈ the corner of the
cell, the weight of that node is
"nearest": 1 for the corner nearest to x along every axis (tₐ ≥ ½ rounds up), else 0: piecewise-constant regions with boundaries half-way between centres;"simplex": barycentric weight in the Kuhn (Freudenthal) triangulation of the cell, which splits it along its main diagonal, max(0, min_{δₐ=1} tₐ − max_{δₐ=0} tₐ) (empty min = 1, empty max = 0): piecewise-linear interpolation on simplices;"multilinear": ∏ₐ (tₐ if δₐ = 1 else 1 − tₐ).
All three are non-negative and sum to 1 at every position.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
centres
|
sequence of Tensor
|
Node positions per axis, increasing. |
required |
coords
|
sequence of Tensor
|
Positions per axis (an open grid: the weights are evaluated at
their outer product), in the same units as |
required |
kind
|
(nearest, simplex, multilinear)
|
Interpolation scheme. |
"nearest"
|
Returns:
| Name | Type | Description |
|---|---|---|
nodes |
Tensor
|
Multi-indices |
weights |
Tensor
|
Their weights, |
object_positions
object_positions(shape, kernel, *, device=None)
Position of each object pixel of a padded block, per axis.
The object grid of
PaddedConvolution and
ShiftVariantConvolution
has N ≥ L + K − 1 pixels per axis. Index q < L is the block pixel q;
the margin is stored periodically: the K − 1 − K // 2 pixels before
the block at the end of the grid, the K // 2 pixels after it right
after the block. Pixels that reach no block pixel are given positions
after the block.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
shape
|
sequence of int
|
Block shape L. |
required |
kernel
|
sequence of int
|
Kernel shape K. |
required |
device
|
optional
|
Device of the result. |
None
|
Returns:
| Type | Description |
|---|---|
tuple of Tensor
|
Per axis, the position (float64, relative to the first block pixel) of each of the N object pixels. |
optimal_circulant
optimal_circulant(kernel, shape)
Eigenvalues of the optimal block-circulant approximation of a blur.
The convolution with kernel on a region of shape ρ (zero boundary)
is a block-Toeplitz matrix with Toeplitz blocks T. The block-circulant
matrix C with circulant blocks closest to T in Frobenius norm (Chan &
Olkin 1993) has first column
c(j) = ∑_{d ≡ j mod ρ} ∏ₐ (1 − |dₐ|/ρₐ) k(d),
k(d) the kernel at offset d from its centre (index K // 2). Its
eigenvalues are the DFT of c.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
kernel
|
Tensor
|
Kernel |
required |
shape
|
sequence of int
|
Region shape ρ. |
required |
Returns:
| Type | Description |
|---|---|
Tensor
|
Eigenvalues as an |
cgls
cgls(data, op, n_iter, *, precond=None, callback=None)
Conjugate gradients for least squares, optionally preconditioned.
Minimises ‖H f − y‖² by CG on the normal equations (CGLS, Björck), from f⁽⁰⁾ = 0, with the right preconditioner P = C⁻¹: the iteration runs on z with f = P z,
s₀ = Pᵀ Hᵀ e₀, p₀ = s₀,
tₖ = P pₖ, qₖ = H tₖ, αₖ = ‖sₖ‖² / ‖qₖ‖²,
fₖ₊₁ = fₖ + αₖ tₖ, eₖ₊₁ = eₖ − αₖ qₖ,
sₖ₊₁ = Pᵀ Hᵀ eₖ₊₁, pₖ₊₁ = sₖ₊₁ + (‖sₖ₊₁‖²/‖sₖ‖²) pₖ,
with e₀ = y the residual y − H fₖ.
Stopping early regularises the solution. Inner products are accumulated in float64.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Tensor
|
Observed block y, |
required |
op
|
ShiftVariantConvolution or PaddedConvolution
|
Blur operator H. |
required |
n_iter
|
int
|
Number of iterations. |
required |
precond
|
RegionPreconditioner
|
Preconditioner C (default: none, plain CGLS). |
None
|
callback
|
callable
|
|
None
|
Returns:
| Name | Type | Description |
|---|---|---|
f |
Tensor
|
Estimate on |
n |
int
|
Number of iterations made (fewer than |
next_fast_len
next_fast_len(n)
transfer_function
transfer_function(psf, grid)
Transfer function of a PSF on a periodic grid (half spectrum).
The PSF S, of shape K and centred at index K // 2, is placed on a
grid of shape N ≥ K with its centre at the origin (wrapped around),
and
H(ν) = ∑ⱼ S(j − K//2) e^{−2πi ν·j}, νₐ = kₐ / Nₐ,
is returned for the frequencies of torch.fft.rfftn (the last dim
holds N₋₁ // 2 + 1 of them). Multiplying the spectrum of an image by
H is the circular convolution with S.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
psf
|
Tensor
|
Point spread function, |
required |
grid
|
sequence of int
|
Grid shape N, one entry per PSF dim, with N ≥ K. |
required |
Returns:
| Type | Description |
|---|---|
Tensor
|
Complex tensor of shape |
smooth_periodic_extension
smooth_periodic_extension(data, grid, mirror=0)
Extend a block to a larger grid so that it is smooth when wrapped.
Along each of the trailing len(grid) dims, in turn, the block
x₀ … x_{L−1} is continued past both of its ends by mirror reflection
over m samples (x_{L−1+t} = x_{L−1−t} and x₋ₜ = xₜ, t = 1 … m), and
the two reflections are joined across the remaining g = N − L − 2m
samples by a raised-cosine blend from a = x_{L−1−m} to b = xₘ,
a + w(t) (b − a), w(t) = (1 − cos(π t / (g + 1))) / 2,
t = 1 … g.
The left reflection is stored at the end of the grid (index −t), so the periodic continuation of the result is continuous everywhere and the samples within m of the block edges see a mirror image of the data rather than a jump: a filter applied by FFT does not ring at the edges (apodisation of the boundary).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Tensor
|
Block |
required |
grid
|
sequence of int
|
Extended shape N ≥ L + 2m of the trailing dims. |
required |
mirror
|
int or sequence of int
|
Reflection width m per dim, reduced to L − 1 for short blocks. |
0
|
Returns:
| Type | Description |
|---|---|
Tensor
|
|
frequencies
frequencies(grid, *, dtype=float64, device=None)
Frequencies ν (cycles per pixel) of the half spectrum of a grid.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
grid
|
sequence of int
|
Grid shape N. |
required |
dtype
|
optional
|
Backend of the result. |
float64
|
device
|
optional
|
Backend of the result. |
float64
|
Returns:
| Type | Description |
|---|---|
tuple of Tensor
|
One tensor per dim, broadcastable to the shape of
|
laplacian_power
laplacian_power(freqs)
|L(ν)|² of the discrete Laplacian (2d + 1 point stencil).
L(ν) = −∑ₐ 4 sin²(π νₐ), |L(ν)|² = (∑ₐ 4 sin²(π νₐ))²,
the transfer function of the stencil with −2d at the centre and 1 at each of the 2d nearest neighbours (unit pixel spacing).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
freqs
|
sequence of Tensor
|
Frequencies per dim, as returned by
|
required |
Returns:
| Type | Description |
|---|---|
Tensor
|
|L(ν)|², broadcast over the frequency grid. |
linear_filter
linear_filter(otf, penalty)
Spectrum of the regularised inverse filter.
R(ν) = H*(ν) / (|H(ν)|² + P(ν)),
with R = 0 where the denominator vanishes (frequencies at which neither the PSF nor the penalty carries information).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
otf
|
Tensor
|
Transfer function H (complex). |
required |
penalty
|
Tensor or float
|
P(ν) ≥ 0, broadcastable to |
required |
Returns:
| Type | Description |
|---|---|
Tensor
|
R, complex, shaped like |
rl_step
rl_step(f, data, op, *, inv_norm, background=0.0, damping=1.0, mu=None, flat=None, back=None, penalty=None)
One Richardson–Lucy update on a block.
f ← f · (1 − ε + ε c), c = Hᵀ[y / (H f + b)] / Hᵀ1,
with ε = damping (ε = 1: the plain update f ← f · c). With a flat
field β, the model is y ~ Poisson(β·H f + b) and
c = Hᵀ[β·y / (β·H f + b)] / Hᵀβ (Snyder et al. 1993, Eq. 15).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
f
|
Tensor
|
Current estimate on the object grid |
required |
data
|
Tensor
|
Observed block y, |
required |
op
|
PaddedConvolution
|
Blur operator H. |
required |
inv_norm
|
Tensor
|
1 / Hᵀ1 (1 / Hᵀβ with a flat field) on the object grid, 0 where it vanishes (object pixels that do not reach the block). |
required |
background
|
Tensor or float
|
Background b added to H f (broadcasts to the block). |
0.0
|
damping
|
float
|
Fraction ε ∈ (0, 1] of the multiplicative correction applied. |
1.0
|
mu
|
Tensor
|
H f + b (β·H f + b) if already computed (e.g. for a stopping test). |
None
|
flat
|
Tensor
|
Flat field β ≥ 0 on the block (detection efficiency per pixel). |
None
|
back
|
callable
|
Back projector B, block |
None
|
penalty
|
callable
|
Denominator d(f) > 0 of a one-step-late regularised update (Green 1990), evaluated at the current estimate: c ← c / d(f) before damping. Default: none (d = 1). |
None
|
Returns:
| Type | Description |
|---|---|
Tensor
|
Updated estimate, non-negative (negative values of an unmatched update are set to 0). |
rl_block
rl_block(data, op, start, *, n_iter=None, alpha=0.05, max_iter=100, background=0.0, damping=1.0, flat=None, expect=None, variance=0.0, back=None, accelerate=False, trace=None, penalty=None, tol=None, step=None)
Richardson–Lucy iterations on one block, optionally accelerated.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Tensor
|
Observed block y (counts), |
required |
op
|
PaddedConvolution
|
Blur operator H. With a |
required |
start
|
float or Tensor
|
Starting estimate f⁽⁰⁾ > 0: a constant or a tensor on |
required |
n_iter
|
int
|
Fixed number of iterations. None: stop at the first r for which
P(χ² > χ²(f⁽ʳ⁾)) ≥ |
None
|
alpha
|
float
|
Significance level of the χ² stopping test. |
0.05
|
max_iter
|
int
|
Iteration cap of the χ² stopping rule. |
100
|
background
|
Tensor or float
|
Background b of the model y ~ Poisson(H f + b). |
0.0
|
damping
|
float
|
Fraction ε ∈ (0, 1] of the correction applied (see
|
1.0
|
flat
|
Tensor
|
Flat field β of the model y ~ Poisson(β·H f + b), on the block. |
None
|
expect
|
callable
|
E-step for data observed through extra noise: maps the expected
counts μ = β·H f + b to the conditional mean of the counts given
the data, used in place of |
None
|
variance
|
Tensor or float
|
Variance of additive Gaussian noise on |
0.0
|
back
|
callable
|
Unmatched back projector B used in place of Hᵀ, normalised by B1
(see |
None
|
accelerate
|
bool
|
Biggs–Andrews vector extrapolation (see
|
False
|
trace
|
dict
|
Filled with per-update diagnostics: |
None
|
penalty
|
callable
|
Denominator of a one-step-late regularised update (see
|
None
|
tol
|
float
|
With |
None
|
step
|
callable
|
Update used in place of |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
f |
Tensor
|
Estimate on the object grid |
n |
int
|
Number of updates applied. |
tv_curvature
tv_curvature(f, ndim, *, epsilon=None)
Curvature term div(∇f / |∇f|) of the total variation.
Discretised with forward differences for the gradient and backward differences for the divergence (its negative adjoint), periodic on the grid:
(∇f)ₖ(x) = f(x + eₖ) − f(x),
nₖ = (∇f)ₖ / max(|∇f|, ε),
div n (x) = ∑ₖ nₖ(x) − nₖ(x − eₖ),
with |∇f| the Euclidean norm over the ndim trailing axes. Where
|∇f| ≤ ε the unit normal n is taken as (∇f)/ε, i.e. it vanishes
with the gradient. Since |nₖ| ≤ 1, |div n| ≤ d + √d (d = ndim).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
f
|
Tensor
|
Image, |
required |
ndim
|
int
|
Number of trailing (spatial) axes. |
required |
epsilon
|
float
|
Floor ε of |∇f|. Default: ε = eps · max|f|, with eps the machine epsilon of the dtype of f: a floor at the round-off level of the working dtype, only to avoid 0/0 (not in the paper). |
None
|
Returns:
| Type | Description |
|---|---|
Tensor
|
div(∇f / |∇f|), same shape as |
biggs_andrews_alpha
biggs_andrews_alpha(g, g_prev)
Acceleration parameter of Biggs and Andrews (1997, Eq. 10).
See Biggs and Andrews (1997, Eq. 10).
αₖ = ∑ gₖ₋₁ · gₖ₋₂ / ∑ gₖ₋₂ · gₖ₋₂, clipped to [0, 1],
with gₖ = ψ(yₖ) − yₖ the change made by the k-th iteration ψ. A negative value is set to 0, which stops the extrapolation until the successive changes point the same way again; the upper bound keeps the predicted step from growing exponentially. The sums are accumulated in float64.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
g
|
Tensor
|
Last change gₖ₋₁. |
required |
g_prev
|
Tensor
|
Change before it, gₖ₋₂. |
required |
Returns:
| Type | Description |
|---|---|
float
|
αₖ ∈ [0, 1]; 0 when gₖ₋₂ = 0. |
chi2_probability
chi2_probability(data, mu)
P(χ² > χ²_obs) of Pearson's statistic for counts.
χ²_obs = ∑ᵢ (yᵢ − μᵢ)² / μᵢ, ν = |Ω| − 1 degrees of freedom,
with |Ω| the number of pixels (Lucy 1974, §IV).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Tensor
|
Observed counts y. |
required |
mu
|
Tensor
|
Expected counts μ > 0, same shape. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Upper tail probability of the χ²(ν) distribution. |
back_projector
back_projector(psf, kind='wiener-butterworth', *, wiener=0.001, cutoff_gain=0.001, order=8, fwhm=None)
Back-projector kernel b of Guo et al. (2020, Supplementary Note 2).
With f the PSF (normalised to unit sum), F = DFT(f) its OTF, k the spatial frequency per axis (cycles per pixel), wₐ the FWHM of the PSF along axis a and k_cₐ = 1/wₐ the cutoff frequency, the transfer functions are
traditional: B = conj(F) (13)
Gaussian: b = exp(−4 ln2 ∑ₐ (xₐ / wₐ)²) (18)
Butterworth: B = 1 / √(1 + ε² [∑ₐ (kₐ/k_cₐ)²]ⁿ) (21)
Wiener–Butterworth:
B = conj(F) / (|F|² + α) · B_Butterworth (25)
with ε² = 1/β² − 1, so that the Butterworth gain at the cutoff is β
(Eq. 23). The kernel is b = DFT⁻¹(B) (Eqs. 22 and 26), normalised to
unit sum (B(0) = 1), as the iteration requires. |F|² is the squared
modulus of the OTF (the paper writes [DFT(f)]², for a real, symmetric
OTF). The FWHM of the PSF is measured with
psf_fwhm unless given.
Sampling. The traditional kernel is the flipped PSF, (*K). The
Gaussian kernel is sampled in space on the grid of shape
kernel_shape K'. The Butterworth
and WB filters are sampled on a DFT grid twice as large as K' along
each axis (F is the DFT of the zero-padded PSF), and b is cropped to
K' around its centre, where its ringing has decayed (the paper
defines b on the image grid, Eq. 12). The frequency response of b
then follows Eq. 21 or 25 whatever the size of the PSF array (to
about 3 % of its peak with the default parameters). The kernels are
centred at index K' // 2.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
psf
|
Tensor
|
Point spread function, |
required |
kind
|
str
|
|
'wiener-butterworth'
|
wiener
|
float
|
Wiener parameter α > 0. |
0.001
|
cutoff_gain
|
float
|
Butterworth gain β ∈ (0, 1) at the cutoff frequency. |
0.001
|
order
|
float
|
Butterworth order n > 0. |
8
|
fwhm
|
float or sequence of float
|
Resolution per axis, in pixels: the cutoff frequency is 1/FWHM.
Default: the FWHM of |
None
|
Returns:
| Type | Description |
|---|---|
Tensor
|
Kernel b, |
kernel_shape
kernel_shape(psf, fwhm=None)
Shape of the filtered back-projector kernels, per axis.
The kernel b = DFT⁻¹(B) of a sharp filter rings over many PSF widths.
It is kept on a support of 12 widths w per axis (odd, and at least
the PSF shape K), with w the larger of the FWHM of the PSF and the
resolution fwhm:
Kₐ' = max(Kₐ, 2 ⌈6 wₐ⌉ + 1).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
psf
|
Tensor
|
Point spread function, |
required |
fwhm
|
float or sequence of float
|
Resolution per axis, in pixels. Default: the FWHM of |
None
|
Returns:
| Type | Description |
|---|---|
tuple of int
|
Kernel shape K'. |
psf_fwhm
psf_fwhm(psf)
Full width at half maximum of a PSF along each axis, in pixels.
The width is measured on the line profile through the maximum of the PSF, between the two half-maximum crossings, located by linear interpolation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
psf
|
Tensor
|
Point spread function, |
required |
Returns:
| Type | Description |
|---|---|
tuple of float
|
FWHM along each axis. |
compound_kernels
compound_kernels(psfs, kernel='efficient')
Back-projection kernels of the multiview updates (compound kernels).
For views v ∈ V with PSFs Pᵥ (N = |V|) and Wᵥ = V ∖ {v} the other views, the kernel bᵥ of the back projection Bᵥ r = r ∗ bᵥ is
"bayesian"(Eq. 37): bᵥ = Pᵥ*, the mirrored PSF (Bᵥ = Hᵥᵀ);"efficient"(Eqs. 102–103): bᵥ = Pᵥ* · ∏_{w ∈ Wᵥ} Pᵥ* ∗ P_w ∗ P_w*;"optimization-1"(Eq. 114): bᵥ = Pᵥ* · ∏_{w ∈ Wᵥ} Pᵥ* ∗ P_w;"optimization-2"(Eq. 115): bᵥ = ∏_{w ∈ V} Pᵥ* = (Pᵥ*)ᴺ,
with ∗ the convolution, · and ∏ pixel-wise products, and P(ξ) = P(−ξ) (equation numbers of the Supplementary Notes of Preibisch et al. 2014). Each kernel is normalised to unit sum. With one view all four are Pᵥ.
Note
The pixel-wise product with Pᵥ* restricts every compound kernel to the support of Pᵥ, so the kernels have the shape of the PSFs. The convolutions are evaluated in float64 by FFT, clamped at 0 (round-off), and every factor of a product is scaled to a unit maximum before multiplying, so that the product of N small values does not underflow; the final normalisation makes the scaling irrelevant.
In MultiviewRL the compound kernels
are used inside the field of view only: on the margin of the
object domain (pixels outside the views), the back projection is
Hᵥᵀ for every variant (see
Multiview).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
psfs
|
sequence of Tensor
|
PSF Pᵥ of each view, |
required |
kernel
|
(bayesian, efficient, optimization - 1, optimization - 2)
|
Variant. |
"bayesian"
|
Returns:
| Type | Description |
|---|---|
list of Tensor
|
Kernel bᵥ of each view, |