Sensor calibration (optix.sensor)
Estimators of the camera noise model and defective pixels, and the variance-stabilising transforms.
Estimators
Camera sensor calibration: offset, gain, read noise, noise-model fits, defective pixels, and variance stabilisation.
Building blocks of these estimators are in optix.sensor.utils.
PoissonGaussian
PoissonGaussian(*, data_range=None, clipped=None, robust=None, mad_correction=None, delta=None, tau=None, eps_reg=None, frame=None, pooled=None, differencing=None, max_iter=None, tol=None, faithful=True, dtype=None, device=None, layout=None)
Bases: Estimator
Poisson–Gaussian noise model σ²(y) = a·y + b fitted from data.
The variance of an observation z with expectation y (both in ADU) is σ²(y) = a·y + b, possibly clipped to the data range. The fit follows Foi et al. (2008): wavelet-domain local estimates of (expectation, standard deviation) on level sets of a smoothed image, then a maximum-likelihood fit of (a, b) to these pairs that accounts for clipping.
The result is estimates["sensor"], a
SensorEstimate with gain = a
and variance = b (the variance extrapolated to 0 ADU) and
offset = None: (a, b) alone do not determine the camera offset.
Fields are shaped (*group, 1, 1). Its meta holds, per group,
the data_range, the final edge threshold tau and
covariance_ok.
Faithful mode
One frame per group, sample standard deviations (Sections III
and V of the paper), clipped model. The opt-in extensions are
pooling over all frames (pooled=True), temporal differencing
(differencing=True) and the MAD estimator of Section VI
(robust=True).
References
- Foi A, Trimeche M, Katkovnik V, Egiazarian K. Practical Poissonian-Gaussian noise modeling and fitting for single-image raw-data. IEEE Trans Image Process 17(10):1737–1754, 2008. doi:10.1109/TIP.2008.2001399
??? quote "BibTeX"
@article{foi2008practical,
author = {Foi, Alessandro and Trimeche, Mejdi and
Katkovnik, Vladimir and Egiazarian, Karen},
title = {Practical {Poissonian-Gaussian} noise modeling
and fitting for single-image raw-data},
journal = {IEEE Transactions on Image Processing},
volume = {17},
number = {10},
pages = {1737--1754},
year = {2008},
doi = {10.1109/TIP.2008.2001399}
}
??? quote "BibTeX"
@article{nelder1965simplex,
author = {Nelder, J. A. and Mead, R.},
title = {A simplex method for function minimization},
journal = {The Computer Journal},
volume = {7},
number = {4},
pages = {308--313},
year = {1965},
doi = {10.1093/comjnl/7.4.308}
}
Attributes:
| Name | Type | Description |
|---|---|---|
estimates |
dict
|
|
covariance |
dict of tuple to Tensor
|
Per group, the 2×2 large-sample covariance of (a, b) in ADU: the
inverse Hessian of −log L at the estimate, by central
differences with steps of half a standard error (not part of
the paper). All NaN, with a |
pairs |
dict of tuple to Pairs
|
Per group, the level-set estimates (ŷᵢ, σ̂ᵢ) in normalised units and their variance factors cᵢ, dᵢ. |
history |
History
|
log L of the best simplex vertex at each Nelder–Mead iteration (all groups in sequence). |
Set up the fit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data_range
|
(float, float) or auto
|
Data values (ADU) mapped to 0 and 1: the normalised range of
Section IV-A, whose extremes are "the maximum and minimum
pixel values for the considered noisy image format"; with
|
None
|
clipped
|
bool
|
Use the clipped observation model z̃ = max(0, min(z, 1)) (Sections IV–V). It reduces to the basic model away from the bounds. Default True. |
None
|
robust
|
bool
|
MAD estimates σ̂ᵐᵃᵈ (Section VI) instead of sample standard
deviations. Default False. Incompatible with |
None
|
mad_correction
|
(paper, exact)
|
Factor (κ̌ᵐᵃᵈ)² of the unbiased variance estimate (κ̌ᵐᵃᵈ σ̂ᵐᵃᵈ)²
that the robust least-squares initialisation uses (Section
VI-A.2). |
"paper"
|
delta
|
float
|
Width Δ of the level sets, Eq. (13). Default 1/300, the value of the paper's example (Fig. 4). |
None
|
tau
|
float
|
Edge threshold τ of Eq. (12). Not specified in the paper; default 0.25, which with the 9×9 kernels used excludes about 0.05 % of the coefficients of pure white noise. It is doubled while fewer than two level sets are found (footnote 2). |
None
|
eps_reg
|
float
|
ε_reg of Eq. (21), in normalised units. Not specified in the paper; default 10⁻⁶. |
None
|
frame
|
int
|
Frame (in the flattened sample axes) used by the single-image fit. Default 0. |
None
|
pooled
|
bool
|
Extension (not in the paper): merge the level-set statistics
of every frame of a group (streamed with
|
None
|
differencing
|
bool
|
Extension (not in the paper): use consecutive frame pairs; the level sets and ŷ come from their mean, σ̂ from the detail coefficients of their difference divided by √2, which removes the scene texture from σ̂. Default False. |
None
|
max_iter
|
(int, float)
|
Nelder–Mead budget and tolerance (not specified in the paper). Defaults 500 and 10⁻¹⁰. |
None
|
tol
|
(int, float)
|
Nelder–Mead budget and tolerance (not specified in the paper). Defaults 500 and 10⁻¹⁰. |
None
|
faithful
|
bool
|
Preset: |
True
|
dtype
|
optional
|
Working backend of the wavelet-domain processing. The ML fit itself is in float64. |
None
|
device
|
optional
|
Working backend of the wavelet-domain processing. The ML fit itself is in float64. |
None
|
layout
|
Layout
|
Axis roles of the data. Exactly two spatial axes. |
None
|
SCMOSCalibration
SCMOSCalibration(*, robust=None, confidence=None, ddof=None, faithful=True, dtype=None, device=None, layout=None)
Bases: CalibrationEstimator
Pixel-wise sCMOS camera calibration (Huang et al., 2013).
After Huang et al. 2013.
Each pixel follows
ADU = g·Poisson(λ) + o + 𝒩(0, var),
so that E = g·λ + o and Var = g²·λ + var = g·(E − o) + var.
- Offset o: the per-pixel temporal mean of a dark stack of M frames, o = (1/M)·∑ₘ sᵐ (Supplementary Note, Eq. 2.1).
- Read variance var: the per-pixel temporal variance of the same stack, var = (1/M)·∑ₘ (sᵐ)² − o² (Eq. 2.2). The paper used 60,000 dark frames.
- Gain g: per-pixel least-squares slope, through the origin, of the
variance excess vᵏ − var on the mean excess D̄ᵏ − o over the
illumination levels k = 1, …, K, D̄ᵏ and vᵏ being the per-pixel
temporal mean and variance of the stack at level k (Eq. 2.3–2.5;
see
gain_regression). The paper used 15 levels of 20,000 frames, ≈ 20 to 200 photons per pixel.
apply converts data to
photoelectrons, (ADU − o)/g.
Gain estimate
The gain of each pixel minimises the unweighted sum of squares
∑ₖ ((vᵏ − var) − g·(D̄ᵏ − o))² over the K illumination levels, a
regression through the origin with equal weight per level
(Supplementary Note, Section 2.3, Eq. 2.3), solved in closed form
as ĝ = ∑ₖ (D̄ᵏ − o)·(vᵏ − var) / ∑ₖ (D̄ᵏ − o)² (Eq. 2.5). All
temporal variances (dark and illuminated) divide by the number of
frames M, as in Eq. 2.2; ddof=1 (extension) divides by M − 1
instead.
Note
fit(levels, dark=darks): levels is a sequence of stacks, one
per illumination level (each with at least two samples per group),
darks a stack of dark frames. Every stack is streamed once
(Welford/Pébay moments). Maps are (*group, *spatial).
References
- Huang F, Hartwich TMP, Rivera-Molina FE, Lin Y, Duim WC, Long JJ, Uchil PD, Myers JR, Baird MA, Mothes W, Davidson MW, Toomre D, Bewersdorf J. Video-rate nanoscopy using sCMOS camera-specific single-molecule localization algorithms. Nat Methods 10(7):653–658, 2013. doi:10.1038/nmeth.2488 Supplementary Note, Section 2 "Characterization of sCMOS Camera", Eq. 2.1–2.5.
BibTeX
@article{huang2013video,
author = {Huang, Fang and Hartwich, Tobias M. P. and
Rivera-Molina, Felix E. and Lin, Yu and
Duim, Whitney C. and Long, Jane J. and
Uchil, Pradeep D. and Myers, Jordan R. and
Baird, Michelle A. and Mothes, Walther and
Davidson, Michael W. and Toomre, Derek and
Bewersdorf, Joerg},
title = {Video-rate nanoscopy using {sCMOS}
camera-specific single-molecule localization
algorithms},
journal = {Nature Methods},
volume = {10}, number = {7}, pages = {653--658},
year = {2013}, doi = {10.1038/nmeth.2488}
}
Configure the calibration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
robust
|
(none, huber, theil - sen)
|
Regression of the gain (see
|
"none"
|
confidence
|
float
|
Extension: flag as |
None
|
ddof
|
(0, 1)
|
Delta degrees of freedom of the temporal variances: they
divide by M − |
0
|
faithful
|
bool
|
See |
True
|
dtype
|
bool
|
See |
True
|
device
|
bool
|
See |
True
|
layout
|
bool
|
See |
True
|
PhotonTransferCurve
PhotonTransferCurve(*, fit_range=None, quantization=None, max_value=None, saturation_fraction=None, saturation=None, temporal=None, highpass=None, spline_intervals=None, per_pixel=None, faithful=True, dtype=None, device=None, layout=None)
Bases: CalibrationEstimator
Photon-transfer curve of a camera (EMVA 1288 Release 4.0 Linear).
The temporal variance of the digital signal is linear in its mean (EMVA 1288 R4.0 Linear, Eq. (15)):
σ²_y = K²·σ²_d + σ²_q + K·(μ_y − μ_y.dark), σ²_q = 1/12 DN²,
with K the overall system gain (DN per electron) and σ_d the read noise in electrons; σ²_y.dark = K²·σ²_d + σ²_q (in optix notation, K = g and σ²_d = σ² / g²).
Procedure (faithful mode, Sections 2.5, 4.2, 6.6, 6.9 and 8):
- every level and the dark stack: μ_y and σ²_y from the first two
images (Eqs. (16), (18), with the mean-difference correction and
1/(2NM) normalisation), see
pair_stats; - saturation μ_y.sat: the largest mean gray value whose two images
have at most
saturation_fraction(0.2 %) of their pixels at the maximum value (Section 6.6); the maximum ismax_value, or the largest value observed in the levels; - K: least-squares line, with unknown offset and slope, of
σ²_y − σ²_y.dark on μ_y − μ_y.dark over the levels from the smallest
up to
fit_range(70 %) of μ_y.sat − μ_y.dark (Eq. (50)); - linearity of the photon-transfer curve: local slopes Kᵢ of a cubic
B-spline regression
(
bspline_slopes) over [0, μ_y.sat − μ_y.dark] at the points of the gain fit; the linear model holds if mean |Kᵢ − K|/K < 3 % (Eq. (51)); - read noise σ_d = √(σ²_y.dark − σ²_q)/K (Eq. (53)); if σ²_y.dark < 0.24 DN², only the upper limit σ_d < 0.40/K (Eq. (54));
- DSNU and PRNU (Section 8, Eqs. (33)-(36), (65)-(67)) from the
highpass-filtered
(
emva_highpass) mean images ⟨y⟩ of the dark stack and of the level closest to 50 % saturation: s²_y = s²_measured − σ²_y.stack/L, DSNU = s_y.dark/K (electrons), PRNU = √(s²_y.50 − s²_y.dark)/(μ_y.50 − μ_y.dark); - with
exposure(photons per pixel): responsivity R (Eq. (49), slope through the origin over the gain-fit range), quantum efficiency η = R/K (Eq. (52)) and the linearity error LE (linearity_error, Eqs. (58)-(63)).
Statistics are per group (Section 6.7: each channel separately). Every stack is streamed once.
Interpretations (optix choices, not stated by the standard)
- The saturation is chosen among the measured levels (the standard sets the exposure to reach 0.1-0.2 %).
- The highpass border crop (see
emva_highpass). - The temporal-noise correction σ²_y.stack/L of Eq. (36) is applied to the highpass-filtered image unchanged.
- The B-spline check uses the mean of |Kᵢ − K|/K (the text) while Eq. (51) prints a sum; Eq. (49) of R4.0 General misses a minus sign in β₃′, the exact derivative is used.
- The dark values are taken at a single exposure time.
References
- European Machine Vision Association. EMVA Standard 1288: Standard for Characterization of Image Sensors and Cameras, Release 4.0 Linear. 16 June 2021. emva.org
- European Machine Vision Association. EMVA Standard 1288: Standard for Characterization of Image Sensors and Cameras, Release 4.0 General. 16 June 2021. emva.org
BibTeX
@techreport{emva1288linear40,
author = {{European Machine Vision Association}},
title = {{EMVA} Standard 1288: Standard for
Characterization of Image Sensors and Cameras,
Release 4.0 Linear},
institution = {EMVA}, year = {2021}, month = jun,
url = {https://www.emva.org/wp-content/uploads/EMVA1288Linear_4.0Release.pdf}
}
@techreport{emva1288general40,
author = {{European Machine Vision Association}},
title = {{EMVA} Standard 1288: Standard for
Characterization of Image Sensors and Cameras,
Release 4.0 General},
institution = {EMVA}, year = {2021}, month = jun,
url = {https://www.emva.org/wp-content/uploads/EMVA1288General_4.0Release.pdf}
}
Attributes:
| Name | Type | Description |
|---|---|---|
curve |
dict of str to Tensor
|
|
Estimates |
`"sensor"`: `offset` (per-pixel dark mean, DN), `variance`
|
|
(read-noise variance σ²_y.dark − σ²_q, DN²) and `gain` (K, per group, |
|
|
or per pixel with `per_pixel`). `meta` holds `gain_stderr`, |
|
|
`gain_offset`, `read_noise_e`, `read_noise_upper_limit`, `dsnu_e`, |
|
|
`prnu`, `saturation` (DN above dark), `linearity_slope_dev` and |
|
|
`linear` (Eq. (51)), and with `exposure` |
`responsivity`,
|
|
`quantum_efficiency`, `linearity_error` (percent). |
|
Configure the photon-transfer analysis.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fit_range
|
float
|
Upper end of the gain fit, as a fraction of the saturation. Paper: 0.7. |
None
|
quantization
|
float
|
Quantisation noise variance σ²_q (DN²). Paper: 1/12 (integer data). Extension: 0 for data that were never quantised. |
None
|
max_value
|
float
|
Maximum possible gray value (e.g. 2ᵏ − 1). Paper: None (found in the data, Section 6.6). |
None
|
saturation_fraction
|
float
|
Largest fraction of pixels at the maximum below saturation. Paper: 0.002 (0.1-0.2 %). |
None
|
saturation
|
(histogram, variance)
|
|
"histogram"
|
temporal
|
(pair, stack)
|
|
"pair"
|
highpass
|
bool
|
Highpass-filter the nonuniformity images (Section 8.1). Paper: True. |
None
|
spline_intervals
|
int
|
Number P of B-spline intervals of the linearity check. Paper: 6 (6 to 8 recommended). |
None
|
per_pixel
|
bool
|
Extension: also fit a per-pixel gain map (per-pixel
photon-transfer curve, as in
|
None
|
faithful
|
bool
|
See |
True
|
dtype
|
bool
|
See |
True
|
device
|
bool
|
See |
True
|
layout
|
bool
|
See |
True
|
fit
fit(data, *, dark=None, exposure=None, layout=None, init=None, callback=None, verbose=False)
Fit the photon-transfer curve.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
sequence of array-like
|
One stack per illumination level (at least two images per level and group). |
required |
dark
|
array - like
|
Dark stack (at least two images; more images give better DSNU estimates, the standard uses L = 100 to 500). |
None
|
exposure
|
sequence of float
|
Mean number of photons per pixel of every level (for the responsivity, quantum efficiency and linearity error). |
None
|
layout
|
Layout | None
|
See |
None
|
init
|
Layout | None
|
See |
None
|
callback
|
Layout | None
|
See |
None
|
verbose
|
Layout | None
|
See |
None
|
Returns:
| Type | Description |
|---|---|
PhotonTransferCurve
|
self |
DefectivePixels
DefectivePixels(*, threshold=None, bimodality=None, faithful=True, dtype=None, device=None, layout=None)
Bases: CalibrationEstimator
Defective, hot and RTS pixel detection from a dark stack.
optix convention
No single publication defines this detector: the tests, thresholds
and replacement rule below are documented optix choices, not a
published algorithm (faithful refers to these defaults).
Per-pixel temporal moments of a dark stack (one streaming pass) give the dark mean m, variance v, skewness g₁ and (non-excess) kurtosis β₂. A pixel is flagged when
"offset": |z(m)| > t (hot or cold pixel),"variance": z(v) > t (noisy pixel),"kurtosis": |z(β₂)| > t (non-Gaussian noise),"rts": bimodal dark histogram, i.e. Sarle's bimodality coefficient (g₁² + 1)/β₂ > b (random telegraph signal; 1/3 for Gaussian noise, 1 for a two-level signal),
with z(x) = (x − med x)/(1.4826·MAD x) the robust z-score over the
pixels of a group (robust_z).
Note
fit(darks). Estimates: "sensor" with defective (union of the
masks), offset and variance (dark mean and variance).
apply replaces defective
pixels with the median of their good neighbours
(replace_defective).
Attributes:
| Name | Type | Description |
|---|---|---|
masks |
dict of str to Tensor
|
The individual boolean |
Configure the detector.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
threshold
|
float
|
Robust z-score threshold t. Default (optix convention) 5. |
None
|
bimodality
|
float
|
Threshold b of the bimodality coefficient. Default (optix convention) 5/9, the value of a uniform distribution. |
None
|
faithful
|
bool
|
See |
True
|
dtype
|
bool
|
See |
True
|
device
|
bool
|
See |
True
|
layout
|
bool
|
See |
True
|
GeneralizedAnscombe
GeneralizedAnscombe(*, alpha=None, sigma=None, mu=None, inverse=None, per_pixel=None, faithful=True, dtype=None, device=None, layout=None)
Bases: CalibrationEstimator
Variance-stabilising transform for Poisson-Gaussian data.
Model (Mäkitalo & Foi 2013, Eq.
(1)): z = α·Poisson(y/α) + 𝒩(μ,
σ²), i.e. a camera with gain α (ADU per electron), offset μ and read
variance σ² (a SensorEstimate).
apply computes
anscombe,
inverse its inverse.
Note
fit(None, init=sensor) only reads the parameters (no data
needed). The exact-inverse table is computed once (float64, CPU)
and interpolated on the data device.
References
- Mäkitalo M, Foi A. Optimal inversion of the Anscombe transformation in low-count Poisson image denoising. IEEE Trans Image Process 20(1):99–109, 2011. doi:10.1109/TIP.2010.2056693
- Mäkitalo M, Foi A. A closed-form approximation of the exact unbiased inverse of the Anscombe variance-stabilizing transformation. IEEE Trans Image Process 20(9):2697–2698, 2011. doi:10.1109/TIP.2011.2121085
- Mäkitalo M, Foi A. Optimal inversion of the generalized Anscombe transformation for Poisson-Gaussian noise. IEEE Trans Image Process 22(1):91–103, 2013. doi:10.1109/TIP.2012.2202675
BibTeX
@article{makitalo2011optimal,
author = {Mäkitalo, Markku and Foi, Alessandro},
title = {Optimal inversion of the {Anscombe} transformation
in low-count {Poisson} image denoising},
journal = {IEEE Transactions on Image Processing},
volume = {20}, number = {1}, pages = {99--109}, year = {2011},
doi = {10.1109/TIP.2010.2056693}
}
@article{makitalo2011closed,
author = {Mäkitalo, Markku and Foi, Alessandro},
title = {A closed-form approximation of the exact unbiased
inverse of the {Anscombe} variance-stabilizing
transformation},
journal = {IEEE Transactions on Image Processing},
volume = {20}, number = {9}, pages = {2697--2698},
year = {2011}, doi = {10.1109/TIP.2011.2121085}
}
@article{makitalo2013optimal,
author = {Mäkitalo, Markku and Foi, Alessandro},
title = {Optimal inversion of the generalized {Anscombe}
transformation for {Poisson-Gaussian} noise},
journal = {IEEE Transactions on Image Processing},
volume = {22}, number = {1}, pages = {91--103}, year = {2013},
doi = {10.1109/TIP.2012.2202675}
}
Configure the transform.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
alpha
|
float
|
Noise parameters; alternatively |
None
|
sigma
|
float
|
Noise parameters; alternatively |
None
|
mu
|
float
|
Noise parameters; alternatively |
None
|
inverse
|
(exact, closed - form, asymptotic, algebraic)
|
Inverse used by |
"exact"
|
per_pixel
|
bool
|
Extension: use the per-pixel maps of the sensor estimate. Paper: False (scalar parameters: the means of the maps). |
None
|
faithful
|
bool
|
See |
True
|
dtype
|
bool
|
See |
True
|
device
|
bool
|
See |
True
|
layout
|
bool
|
See |
True
|
fit
fit(data=None, **kwargs)
Read the noise parameters from init (a SensorEstimate).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
array - like
|
Unused. |
None
|
**kwargs
|
object
|
|
{}
|
Returns:
| Type | Description |
|---|---|
GeneralizedAnscombe
|
self |
inverse
inverse(data, out=None)
Inverse transform (method from the inverse option).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
array - like
|
Transformed data, in the layout of the fit. |
required |
out
|
writable array-like
|
|
None
|
Returns:
| Type | Description |
|---|---|
writable array-like
|
|
DarkFlatCalibration is also exported here; it is documented under Shading correction.
Transforms
Camera sensor calibration: offset, gain, read noise, noise-model fits, defective pixels, and variance stabilisation.
Building blocks of these estimators are in optix.sensor.utils.
anscombe
anscombe(z, alpha=1.0, sigma=0.0, mu=0.0)
Generalised Anscombe transform (pointwise).
For z = α·Poisson(y/α) + 𝒩(μ, σ²) (Mäkitalo & Foi 2013, Eq. (3)):
f(z) = (2/α)·√max(0, α·z + 3/8·α² + σ² − α·μ),
whose noise is approximately standard normal.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
z
|
Tensor
|
Data. |
required |
alpha
|
Tensor or float
|
Gain α, Gaussian standard deviation σ and mean μ; scalars or maps
broadcastable to |
1.0
|
sigma
|
Tensor or float
|
Gain α, Gaussian standard deviation σ and mean μ; scalars or maps
broadcastable to |
1.0
|
mu
|
Tensor or float
|
Gain α, Gaussian standard deviation σ and mean μ; scalars or maps
broadcastable to |
1.0
|
Returns:
| Type | Description |
|---|---|
Tensor
|
|
inverse_anscombe
inverse_anscombe(d, alpha=1.0, sigma=0.0, mu=0.0, *, method='exact', table=None)
Inverse of the generalised Anscombe transform.
Works in normalised units σ = σ̂/α (Mäkitalo & Foi 2013, Eq. (4)) and returns α·ŷ + μ, an estimate of E[z].
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
d
|
Tensor
|
Transformed (typically denoised) data D. |
required |
alpha
|
Tensor or float
|
As in |
1.0
|
sigma
|
Tensor or float
|
As in |
1.0
|
mu
|
Tensor or float
|
As in |
1.0
|
method
|
(exact, closed - form, asymptotic, algebraic)
|
The inverses of Mäkitalo & Foi 2013:
|
"exact"
|
table
|
tuple
|
|
None
|
Returns:
| Type | Description |
|---|---|
Tensor
|
|
replace_defective
replace_defective(y, defective)
Replace defective pixels by the median of their good neighbours.
Optix convention (no single publication).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
y
|
(n, *spatial) Tensor
|
Frames. |
required |
defective
|
(*spatial) bool Tensor
|
|
required |
Returns:
| Type | Description |
|---|---|
Tensor
|
Copy of |
Utilities
No stability promise
optix.sensor.utils holds building blocks of the estimators above; they may change without notice.
Building blocks of the sensor calibration estimators.
Semi-public: these may change without notice.
SegmentStats
SegmentStats(segments)
Mergeable per-segment statistics of (value, noise) pairs.
For each segment i (for example a level set), this accumulates
the count nᵢ, the mean of value (for example approximation
coefficients, giving the local mean) and the mean and variance of
noise (for example detail coefficients, giving the local standard
deviation).
Note
Each update computes the segment sums in float64 (temporaries the
size of the selected entries only) and centres the noise on its
segment mean before squaring. It then merges them with
Pébay's pairwise formulas
(Moments). The result
does not depend on chunking, up to round-off, and is the same for
float32 and float64 inputs, up to their precision.
Only sufficient statistics of the sample standard deviation are kept. Median-based estimators (such as the MAD) are not mergeable.
Attributes:
| Name | Type | Description |
|---|---|---|
value |
Moments
|
Order-1 moments of |
noise |
Moments
|
Order-2 moments of |
Empty statistics.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
segments
|
int
|
Number of segments; labels are in |
required |
update
update(labels, value, noise, mask=None)
Add a chunk of labelled pairs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
labels
|
Tensor
|
Integer segment of each entry. Entries outside
|
required |
value
|
Tensor
|
Same shape as |
required |
noise
|
Tensor
|
Same shape as |
required |
mask
|
Tensor
|
Boolean; False entries are ignored. |
None
|
Returns:
| Type | Description |
|---|---|
SegmentStats
|
self |
merge
merge(other)
Merge another SegmentStats (same number of segments).
to
to(device=None, dtype=None)
Move the state (in place).
result
result(min_count=2)
Statistics of the segments with at least min_count entries.
Returns:
| Type | Description |
|---|---|
dict
|
|
gain_regression
gain_regression(dmean, dvar, *, robust=None, iterations=20)
Per-pixel slope of the variance on the mean, through the origin.
For every pixel, solves (Huang et al. 2013, Supplementary Note, Eq. 2.3)
ĝ = argmin_g ∑ₖ ((vᵏ − var) − g·(D̄ᵏ − o))²,
with D̄ᵏ − o the mean excess and vᵏ − var the variance excess at illumination level k = 1, …, K. With A = (vᵏ − var)ₖ and B = (D̄ᵏ − o)ₖ, the closed form is (Eq. 2.5)
ĝ = (B·Bᵀ)⁻¹·B·Aᵀ = ∑ₖ Bₖ·Aₖ / ∑ₖ Bₖ².
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dmean
|
(K, ...) Tensor
|
Mean minus offset and variance minus read variance, per level. |
required |
dvar
|
(K, ...) Tensor
|
Mean minus offset and variance minus read variance, per level. |
required |
robust
|
(None, huber, theil - sen)
|
None: unweighted least squares (Eq. 2.3). |
None
|
iterations
|
int
|
IRLS iterations for |
20
|
Returns:
| Type | Description |
|---|---|
gain, stderr : (...) Tensor
|
Slope and its standard error √(s²/∑ₖ wₖ·Bₖ²), with s² the residual variance (NaN with a single level). |
pair_stats
pair_stats(data, *, dtype=None, device=None, out_dtype=None)
EMVA 1288 statistics of a stack, in one streaming pass.
With y[0], y[1] the first two images (in storage order) of every group and NM pixels (EMVA 1288 R4.0 Linear, Eqs. (16), (18), (32)):
μ[k] = (1/NM)·∑ y[k],
σ²_y = (1/2NM)·∑ (y[0] − y[1])² − ½·(μ[0] − μ[1])²,
s²_y = (1/NM)·∑ (y[0] − μ[0])·(y[1] − μ[1]),
plus the per-pixel moments of all images (Welford/Pébay).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
array - like or Labeled
|
Stack with at least two images per group. |
required |
dtype
|
optional
|
Working backend and dtype of the results. |
None
|
device
|
optional
|
Working backend and dtype of the results. |
None
|
out_dtype
|
optional
|
Working backend and dtype of the results. |
None
|
Returns:
| Type | Description |
|---|---|
PairStats
|
|
bspline_slopes
bspline_slopes(x, y, xmax, intervals=6)
Slopes of a cubic B-spline regression (EMVA 1288 R4.0 General).
Section 6.6 of Release 4.0 General, Eqs. (44)-(49): over [0, xmax] split into P intervals of width Δ,
y(x) = ∑_{p=0}^{P+2} aₚ·β₃(x/Δ − (p − 1)),
fitted by least squares; the slope is the analytic derivative.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
(Q,) Tensor
|
Data points (Q > P + 3). |
required |
y
|
(Q,) Tensor
|
Data points (Q > P + 3). |
required |
xmax
|
float
|
Right end of the regression range. |
required |
intervals
|
int
|
P (the standard recommends 6 to 8). |
6
|
Returns:
| Type | Description |
|---|---|
(Q,) Tensor
|
dy/dx at |
emva_highpass
emva_highpass(x, nspatial=2)
EMVA 1288 R4.0 highpass filter of a nonuniformity image.
Section 8.1: the image is smoothed by a 7×7 box filter, an 11×11 box filter and a 3×3 binomial filter, one after the other, and the smoothed image is subtracted from the original. Every spatial dim is filtered.
optix convention
Only the part where the filters are exact is returned: 9 pixels are removed at each border, by analogy with the border rule of Release 3.1 (Appendix C.5); Release 4.0 does not state it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
(..., *spatial) Tensor
|
|
required |
nspatial
|
int
|
Number of trailing spatial dims. |
2
|
Returns:
| Type | Description |
|---|---|
(..., *spatial − 18) Tensor
|
|
linearity_error
linearity_error(y, h, ysat, lo=0.05, hi=0.95)
Linearity error LE (EMVA 1288 R4.0 Linear, Section 6.9).
Weighted least squares of y = a₀ + a₁·H with weights 1/y² (Section 6.9, Eqs. (59)-(61)) over the points with y ∈ [0.05, 0.95]·y_sat, relative deviations δ_y = 100·(y − (a₀ + a₁·H))/(a₀ + a₁·H) (Eq. (62)) and LE = mean |δ_y| (Eq. (63)).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
y
|
(Q,) Tensor
|
Mean photo-induced gray values μ_y − μ_y.dark. |
required |
h
|
(Q,) Tensor
|
Exposures (any unit, e.g. photons per pixel). |
required |
ysat
|
float
|
μ_y.sat − μ_y.dark. |
required |
lo
|
float
|
Range, as fractions of |
0.05
|
hi
|
float
|
Range, as fractions of |
0.05
|
Returns:
| Name | Type | Description |
|---|---|---|
le |
float
|
Linearity error in percent. |
delta |
(Q,) Tensor
|
δ_y in percent (NaN outside the range). |
coef |
(float, float)
|
(a₀, a₁). |
bimodality
bimodality(skewness, kurtosis)
Sarle's bimodality coefficient (g₁² + 1)/β₂.
1/3 for a Gaussian, 5/9 for a uniform distribution and 1 for any
two-point distribution (a noiseless random telegraph signal).
kurtosis is the non-excess kurtosis β₂.
robust_z
robust_z(x, nspatial)
(x − median)/(1.4826·MAD) over the spatial dims (per group).
Non-finite values are ignored in the median and MAD.
closed_form_inverse
closed_form_inverse(d, s2=0.0)
Closed-form approximation of the exact unbiased inverse.
Mäkitalo & Foi 2011 letter, Eq. (6), generalised in Mäkitalo & Foi 2013, Eq. (21) (normalised units, σ = σ̂/α):
Ĩ_σ(D) = Ĩ_0(D) − σ²,
Ĩ_0(D) = D²/4 + (1/4)·√(3/2)·D⁻¹ − (11/8)·D⁻² + (5/8)·√(3/2)·D⁻³ − 1/8,
with Ĩ_0(D) = 0 for D < 2·√(3/8) (letter, Section II). As published, Ĩ_σ is not clipped further: it equals −σ² below 2·√(3/8).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
d
|
Tensor
|
Transformed data D. |
required |
s2
|
Tensor or float
|
Normalised Gaussian variance σ² = σ̂²/α². |
0.0
|
Returns:
| Type | Description |
|---|---|
Tensor
|
|
exact_inverse_table
exact_inverse_table(s2, *, ymax=200.0, ny=2000, nd=4096, nquad=2001)
Lookup table of the exact unbiased inverse, normalised units.
For z = Poisson(y) + 𝒩(0, σ²) and f_σ(z) = 2·√max(0, z + 3/8 + σ²), computes (Mäkitalo & Foi 2013, Eq. (10))
E{f_σ(z) | y, σ} = ∑ₖ yᵏ·e⁻ʸ/k! · ∫ f_σ(k + σ·n)·φ(n) dn
on a grid of y (trapezoidal rule over n ∈ [−10, 10]) and inverts it on a uniform grid of D.
Note
Computed in float64 on the CPU.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
s2
|
(S,) Tensor
|
Grid of σ² (normalised: σ̂²/α²). |
required |
ymax
|
float
|
Largest y of the table; above,
|
200.0
|
ny
|
int
|
Sizes of the y grid, of the D grid and of the quadrature. |
2000
|
nd
|
int
|
Sizes of the y grid, of the D grid and of the quadrature. |
2000
|
nquad
|
int
|
Sizes of the y grid, of the D grid and of the quadrature. |
2000
|
Returns:
| Name | Type | Description |
|---|---|---|
dgrid |
(nd,) Tensor
|
Uniform grid of D from 0 to the smallest E{f | ymax}. |
table |
(S, nd) Tensor
|
y such that E{f_σ(z) | y} = D (0 below E{f | 0}). |
to_normalized
to_normalized(a, b, low, scale)
(a, b) in the units of z′ = (z − low)/scale.
σ′²(y′) = (a/scale)·y′ + (a·low + b)/scale².
sensor_estimate
sensor_estimate(a, b, offset=None, *, meta=None)
SensorEstimate for σ²(y) = a·y + b.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
a
|
Tensor or float
|
Slope of the variance function, i.e. the gain (ADU per electron). |
required |
b
|
Tensor or float
|
Variance at y = 0 ADU (ADU²). |
required |
offset
|
Tensor or float
|
Known camera offset (ADU). (a, b) alone do not determine it. |
None
|
Returns:
| Type | Description |
|---|---|
SensorEstimate
|
|