Forward models (optix.models)
Simulators of the blur, camera and shading models that return ground truth as estimates, and phantoms to feed them. See Image formation and noise.
Forward models and simulators returning ground-truth estimates.
Samples depend on the seed and on how the caller chunks the calls.
gaussian_psf
gaussian_psf(shape, sigma, *, dtype=None, device=None)
Sampled Gaussian point spread function.
h(r) ∝ exp(−½ ∑ₐ (rₐ / σₐ)²), with r measured from the centre index
K // 2 along each axis (the convention of the deconvolvers), and
normalised to ∑h = 1.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
shape
|
sequence of int
|
PSF shape K, e.g. (15, 15) or (Z, Y, X). Odd sizes centre the peak on a pixel. |
required |
sigma
|
float or sequence of float
|
Standard deviation σ in pixels, one value or one per axis. FWHM = 2√(2 ln 2) σ ≈ 2.355 σ. |
required |
dtype
|
optional
|
Working backend. |
None
|
device
|
optional
|
Working backend. |
None
|
Returns:
| Type | Description |
|---|---|
(*K) Tensor
|
The PSF h, summing to 1. |
simulate_blur
simulate_blur(x, psf)
Blur a latent image with a PSF: y = h ∗ x.
Linear convolution with zero boundary (no light from outside x), the same as the forward operator of the deconvolvers, so that deconvolving the result is consistent with its simulation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
(..., *spatial) Tensor
|
Latent image; the trailing |
required |
psf
|
(*K) Tensor
|
Point spread function h, centred at |
required |
Returns:
| Type | Description |
|---|---|
Tensor
|
h ∗ x, the shape of |
random_sensor
random_sensor(shape, *, offset=100.0, offset_sd=2.0, read_sd=1.5, gain=0.5, gain_sd=0.0, defective=0.0, seed=None, dtype=None, device=None)
Draw a random sensor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
shape
|
sequence of int
|
Spatial shape (H, W). |
required |
offset
|
float
|
Mean and per-pixel standard deviation of the offset (ADU). |
100.0
|
offset_sd
|
float
|
Mean and per-pixel standard deviation of the offset (ADU). |
100.0
|
read_sd
|
float
|
Read-noise standard deviation (ADU), the same for every pixel. |
1.5
|
gain
|
float
|
Mean and per-pixel standard deviation of the gain (ADU per electron). Gains are kept positive. |
0.5
|
gain_sd
|
float
|
Mean and per-pixel standard deviation of the gain (ADU per electron). Gains are kept positive. |
0.5
|
defective
|
float
|
Fraction of defective pixels. |
0.0
|
seed
|
int
|
|
None
|
dtype
|
optional
|
Working backend. |
None
|
device
|
optional
|
Working backend. |
None
|
Returns:
| Type | Description |
|---|---|
SensorEstimate
|
|
simulate_sensor
simulate_sensor(signal, sensor, *, seed=None, quantize=None)
Simulate camera data from a signal in electrons.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
signal
|
(..., H, W) Tensor
|
Expected number of electrons (≥ 0). |
required |
sensor
|
SensorEstimate
|
Needs |
required |
seed
|
int
|
|
None
|
quantize
|
dtype
|
Integer dtype: round and saturate to its range. |
None
|
Returns:
| Type | Description |
|---|---|
Tensor
|
offset + gain · Poisson(signal) + N(0, variance), in ADU. |
random_shading
random_shading(shape, *, order=3, strength=0.3, dark=0.0, seed=None, dtype=None, device=None)
Draw a smooth random flat field.
flat = exp(f) with f a random combination of the lowest order
DCT-II functions along each dim (no DC term), scaled so that
std(f) = strength, then normalised to mean 1.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
shape
|
sequence of int
|
Spatial shape. |
required |
order
|
int
|
Number of DCT functions per dim. |
3
|
strength
|
float
|
Standard deviation of the log flat field. |
0.3
|
dark
|
float
|
Value of the (constant) dark field, ADU. |
0.0
|
seed
|
int
|
|
None
|
dtype
|
optional
|
Working backend. |
None
|
device
|
optional
|
Working backend. |
None
|
Returns:
| Type | Description |
|---|---|
ShadingEstimate
|
|
simulate_shading
simulate_shading(x, shading)
Apply a shading model: y = f ⊙ (x + bₙ) + d.
The baseline bₙ is in the units of shading.baseline_units (see
ShadingEstimate): with
"raw", the model is y = f · x + d + bₙ.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
(*batch, frames, H, W) Tensor
|
Unshaded signal. |
required |
shading
|
ShadingEstimate
|
Fields that are None are treated as absent terms ( |
required |
Returns:
| Type | Description |
|---|---|
Tensor
|
|
simulate_tiles
simulate_tiles(x, grid, *, overlap=0.1, tile_gain=None, tile_offset=None, spread=(0.2, 0.1), noise=0.0, seed=None)
Cut an image into a grid of overlapping tiles with intensity changes.
Tile i, a crop of x, is recorded as
yᵢ = gᵢ x[crop i] + oᵢ + ε, ε ~ N(0, noise²),
so that the transform that maps every tile back onto x is
aᵢ = 1/gᵢ, cᵢ = −oᵢ/gᵢ.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Tensor
|
|
required |
grid
|
sequence of int
|
Number of tiles along each spatial axis. |
required |
overlap
|
float
|
Fraction of the tile side shared by neighbouring tiles (at least;
tiles are spread to cover |
0.1
|
tile_gain
|
(T,) Tensor or sequence of float
|
Per-tile gᵢ (dimensionless, not the camera gain) and oᵢ (in the
units of |
None
|
tile_offset
|
(T,) Tensor or sequence of float
|
Per-tile gᵢ (dimensionless, not the camera gain) and oᵢ (in the
units of |
None
|
spread
|
(float, float)
|
Spreads of the random gains and offsets. |
(0.2, 0.1)
|
noise
|
float
|
Standard deviation of additive Gaussian noise. |
0.0
|
seed
|
int
|
|
None
|
Returns:
| Name | Type | Description |
|---|---|---|
tiles |
list of Tensor
|
T tiles (all of the same shape). |
positions |
(T, D) Tensor
|
Position of the first pixel of each tile in |
truth |
TileIntensityEstimate
|
|
Phantoms
optix.models.phantoms draws ground-truth specimens: latent images
\(\mathbf{x} \geq 0\) in expected photoelectrons per pixel, to pass through
the simulators above. A scene is a short composition:
from optix.models import phantoms, random_sensor, random_shading
from optix.models import simulate_sensor, simulate_shading
x = phantoms.cells((40, 64, 64), seed=0) + 20 # 40 frames of cells
shading = random_shading((64, 64), seed=1)
y = simulate_sensor(simulate_shading(x, shading), random_sensor((64, 64)))
Numeric phantoms: ground-truth specimens x for the simulators.
Each function draws a latent image x ≥ 0, in expected photoelectrons
per pixel (e⁻): the signal of
simulate_sensor, the unshaded x of
simulate_shading, the object of
simulate_blur. A scene is a short
composition, for example
x = phantoms.cells((40, 64, 64), seed=0) + 10
y = simulate_sensor(simulate_shading(x, shading), sensor, seed=1)
shape is (*sample, *spatial): the trailing ndim dims (2 by
default, 3 for volumes) are the grid Ω, and every leading index (a
frame n = 1…N, say) is an independent draw. Positions are in pixels,
pixel i at the integer coordinates of its index, as the centre K // 2
of gaussian_psf. Random parameters are
drawn on the CPU in float64 from seed, so a seed gives the same
phantom on every device.
cells
cells(shape, count=10, *, radius=6.0, intensity=100.0, variation=0.2, edge=0.5, ndim=2, seed=None, dtype=None, device=None)
Fluorescent cells: bright ellipses (ellipsoids in 3D) on black.
Each cell k has a uniform centre cₖ in the field, a random orientation Rₖ, semi-axes aₖ = radius · exp(0.2 ξ) and a brightness βₖ = intensity · exp(variation · ξ), ξ ~ 𝒩(0, 1). With ρₖ(r) = ‖diag(aₖ)⁻¹ Rₖᵀ (r − cₖ)‖ and āₖ the mean semi-axis,
xᵢ = maxₖ βₖ · sigmoid((1 − ρₖ(rᵢ)) āₖ / edge),
flat-topped objects with soft boundaries; overlapping cells keep the brighter one. Add a constant for autofluorescence.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
shape
|
sequence of int
|
|
required |
count
|
int
|
Number of cells per sample. |
10
|
radius
|
float
|
Typical semi-axis, in pixels. |
6.0
|
intensity
|
float
|
Median brightness (e⁻) and log-normal spread of the cells. |
100.0
|
variation
|
float
|
Median brightness (e⁻) and log-normal spread of the cells. |
100.0
|
edge
|
float
|
Width of the soft boundary, in pixels. |
0.5
|
ndim
|
int
|
Number of trailing spatial dims. |
2
|
seed
|
int
|
|
None
|
dtype
|
optional
|
Working backend. |
None
|
device
|
optional
|
Working backend. |
None
|
Returns:
| Type | Description |
|---|---|
Tensor
|
x, of |
beads
beads(shape, count=40, *, sigma=1.0, brightness=1000.0, separation=0.0, margin=None, ndim=2, seed=None, dtype=None, device=None)
Point-like beads at sub-pixel positions.
Bead k at cₖ is a sampled Gaussian of total brightness β:
xᵢ = ∑ₖ β 𝒩(rᵢ; cₖ, diag σ²),
the image of a sub-resolution bead through a Gaussian PSF h of
standard deviation σ (FWHM ≈ 2.355 σ). For a point source to blur
with another PSF, keep σ small (about 0.5) and use
simulate_blur. Large σ give blobs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
shape
|
sequence of int
|
|
required |
count
|
int
|
Number of beads per sample. |
40
|
sigma
|
float or sequence of float
|
Standard deviation σ in pixels, one value or one per axis. |
1.0
|
brightness
|
float
|
Expected electrons β of one bead, summed over its pixels (sums below β when σ < 0.5 or near the border). |
1000.0
|
separation
|
float
|
Minimum distance between bead centres, in pixels. |
0.0
|
margin
|
float
|
Least distance of the centres to the border, in pixels. Default: 3σ along each axis. |
None
|
ndim
|
int
|
Number of trailing spatial dims. |
2
|
seed
|
int
|
|
None
|
dtype
|
optional
|
Working backend. |
None
|
device
|
optional
|
Working backend. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
x |
Tensor
|
Image of |
positions |
(*sample, count, ndim) Tensor
|
Bead centres cₖ, in pixels. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
filaments
filaments(shape, count=10, *, width=1.0, intensity=100.0, length=None, curvature=0.1, ndim=2, seed=None, dtype=None, device=None)
Filaments: thin curved fibres, fine detail for deconvolution.
Each filament is a smooth random curve, a walk from a uniform start whose unit direction d turns at every step δ:
d ← (d + curvature √δ ξ) / ‖·‖, ξ ~ 𝒩(0, I),
so that the persistence length is of the order of 1 / curvature²
pixels. The curve is drawn as a tube with a Gaussian profile of
standard deviation width and a peak of about intensity (a
straight filament); crossings add up.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
shape
|
sequence of int
|
|
required |
count
|
int
|
Number of filaments per sample. |
10
|
width
|
float
|
Standard deviation of the cross-section, in pixels. |
1.0
|
intensity
|
float
|
Peak value (e⁻) of an isolated filament. |
100.0
|
length
|
float
|
Length of each filament, in pixels. Default: the largest spatial size. |
None
|
curvature
|
float
|
Change of direction over one pixel, in radians (rms). |
0.1
|
ndim
|
int
|
Number of trailing spatial dims. |
2
|
seed
|
int
|
|
None
|
dtype
|
optional
|
Working backend. |
None
|
device
|
optional
|
Working backend. |
None
|
Returns:
| Type | Description |
|---|---|
Tensor
|
x, of |
background
background(shape, *, level=20.0, variation=0.3, order=3, ndim=2, seed=None, dtype=None, device=None)
Smooth background: haze, autofluorescence, out-of-focus light.
x = level · exp(f) / mean(exp(f)), with f a random combination of
the lowest order DCT-II functions per spatial dim (no constant
term) scaled to std(f) = variation: the same smooth field as the
flat of random_shading, but part of
the specimen.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
shape
|
sequence of int
|
|
required |
level
|
float
|
Mean of x over Ω (e⁻), for every sample. |
20.0
|
variation
|
float
|
Standard deviation of log x. |
0.3
|
order
|
int
|
Number of DCT functions per dim: larger is less smooth. |
3
|
ndim
|
int
|
Number of trailing spatial dims. |
2
|
seed
|
int
|
|
None
|
dtype
|
optional
|
Working backend. |
None
|
device
|
optional
|
Working backend. |
None
|
Returns:
| Type | Description |
|---|---|
Tensor
|
x > 0, of |
stripes
stripes(shape, *, axis=-2, strength=5.0, fraction=1.0, ndim=2, seed=None, dtype=None, device=None)
Stripe artefact s, constant along one axis.
Every line along axis (a column of a frame, for the default
axis=-2) carries one offset, 𝒩(0, strength²) on a random
fraction of the lines and 0 on the others, as left by uneven
detector rows or by the shadows of a light sheet. The destriping
estimators model the recording as y = x + s; for multiplicative
shadows, use x ⊙ exp(s) with a small strength.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
shape
|
sequence of int
|
|
required |
axis
|
int
|
Spatial axis the stripes run along, as |
-2
|
strength
|
float
|
Standard deviation of the offsets, in the units of x. |
5.0
|
fraction
|
float
|
Fraction of the lines that carry a stripe, in [0, 1]. |
1.0
|
ndim
|
int
|
Number of trailing spatial dims. |
2
|
seed
|
int
|
|
None
|
dtype
|
optional
|
Working backend. |
None
|
device
|
optional
|
Working backend. |
None
|
Returns:
| Type | Description |
|---|---|
Tensor
|
s, of |
ramp
ramp(shape, *, low=0.0, high=1000.0, axis=-1, dtype=None, device=None)
Linear ramp from low to high along one axis.
A target that covers a range of intensities in a single picture, for noise calibration (the photon-transfer and variance-stabilising pages) or a known illumination gradient.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
shape
|
sequence of int
|
Shape of x, sample dims included. |
required |
low
|
float
|
Values (e⁻) at the first and last index of |
0.0
|
high
|
float
|
Values (e⁻) at the first and last index of |
0.0
|
axis
|
int
|
Axis of the ramp. |
-1
|
dtype
|
optional
|
Working backend. |
None
|
device
|
optional
|
Working backend. |
None
|
Returns:
| Type | Description |
|---|---|
Tensor
|
x, of |