Linear operators parallelproj.operators

This module defines the LinearOperator base class used throughout parallelproj. The public interface is op(x) (forward) and op.adjoint(y) – or the adjoint operator op.H – while subclasses implement the private _apply / _adjoint. Composite operators such as CompositeLinearOperator let you chain a projector with image-based models (e.g. a GaussianFilterOperator resolution model or an ElementwiseMultiplicationOperator for attenuation) while the correct adjoint is assembled automatically. Operators act on float32 array-API arrays on CPU or GPU; the PET projectors in PET projectors parallelproj.projectors are themselves linear operators.

Array-API-compatible linear operator abstractions and concrete implementations.

Provides the LinearOperator abstract base class – with forward and adjoint application, norm estimation via power iteration, and an adjointness test – together with concrete operators: dense matrix multiplication, element-wise multiplication, Gaussian filtering, forward finite differences, operator composition, and vertical stacking. All implementations dispatch correctly across NumPy, CuPy, and PyTorch.

class parallelproj.operators.AdjointLinearOperator(operator: LinearOperator)[source]

Bases: LinearOperator

Adjoint of a linear operator

Wraps an existing LinearOperator so that __call__ applies \(A^H\) and adjoint applies \(A\). The scale of this operator is always the complex conjugate of the wrapped operator’s scale; setting the scale on either one propagates to the other.

Use the LinearOperator.H property rather than constructing this class directly.

Examples

init method

Parameters:

operator (LinearOperator) – the operator whose adjoint is to be represented

Examples

property H: AdjointLinearOperator

adjoint operator \(A^H\)

__call__(x: Array) Array

alias to apply(x)

Examples

Parameters:

x (Array)

Return type:

Array

adjoint(y: Array) Array[source]

(scaled) adjoint step \(x = \alpha A y\).

Parameters:

y (Array)

Return type:

Array

Examples

adjointness_test(xp: ModuleType | None = None, dev: str | None = None, verbose: bool = False, iscomplex: bool = False, dtype: type | None = None, **kwargs) bool

test whether the adjoint is correctly implemented

Parameters:
  • xp (ModuleType, optional) – array module to use. Defaults to the operator’s own namespace (self.xp) when it exposes one; otherwise must be given.

  • dev (str, optional) – device (cpu or cuda). Defaults to the operator’s own device (self.dev) when it exposes one, else the default device.

  • verbose (bool, optional) – verbose output

  • iscomplex (bool, optional) – use complex arrays

  • dtype (type | None, optional) – data type of the arrays

  • **kwargs (dict) – passed to np.isclose

Returns:

whether the adjoint is correctly implemented

Return type:

bool

Examples

apply(x: Array) Array[source]

(scaled) forward step \(y = \overline{\alpha} A^H x\).

Uses the property scale (= conj(A.scale)) rather than the instance variable so that scale changes on either A or A.H are always reflected.

Parameters:

x (Array)

Return type:

Array

Examples

property in_shape: tuple[int, ...]

Output shape of the wrapped operator (adjoint swaps in/out).

norm(xp: ModuleType | None = None, dev: str | None = None, num_iter: int = 30, iscomplex: bool = False, verbose: bool = False) float

estimate norm of the linear operator using power iterations

Parameters:
  • xp (ModuleType, optional) – array module to use. Defaults to the operator’s own namespace (self.xp) when it exposes one; otherwise must be given.

  • dev (str, optional) – device (cpu or cuda). Defaults to the operator’s own device (self.dev) when it exposes one, else the default device.

  • num_iter (int, optional) – number of power iterations

  • iscomplex (bool, optional) – use complex arrays

  • verbose (bool, optional) – verbose output

Returns:

the norm of the linear operator

Return type:

float

Examples

property out_shape: tuple[int, ...]

Input shape of the wrapped operator (adjoint swaps in/out).

property scale: float | complex

Complex conjugate of the wrapped operator’s scale.

Both A.H.scale and A.scale read from and write to the same underlying value on the wrapped operator, so they are always consistent:

  • A.H.scale returns conj(A.scale)

  • A.H.scale = c sets A.scale = conj(c)

  • Setting A.scale = c is automatically reflected in A.H.scale

The apply() and adjoint() methods on A.H read this property (not the instance variable _scale) so the coupling is always active.

class parallelproj.operators.CompositeLinearOperator(operators: Sequence[LinearOperator])[source]

Bases: LinearOperator

Composite Linear Operator defined by a sequence of Linear Operators

Given a Sequence of operators

\[A^0, A^1, \ldots, A^{n-1}\]

the composite linear operator is defined as

\[A(x) = A^0( A^1( ... ( A^{n-1}(x) ) ) )\]

Examples

Detector mashing: fewer, bigger virtual detectors

Detector mashing: fewer, bigger virtual detectors

TOF-bin mashing: fewer, wider time-of-flight bins

TOF-bin mashing: fewer, wider time-of-flight bins

PET non-TOF sinogram projector

PET non-TOF sinogram projector

PET TOF sinogram projector

PET TOF sinogram projector

PET listmode projector (non-TOF and TOF)

PET listmode projector (non-TOF and TOF)

Convergence comparison: MLEM vs OSEM vs SVRG

Convergence comparison: MLEM vs OSEM vs SVRG

Convergence comparison: SGD vs SVRG with logcosh regularization

Convergence comparison: SGD vs SVRG with logcosh regularization

PDHG and SPDHG for PET reconstruction with a directional TV prior

PDHG and SPDHG for PET reconstruction with a directional TV prior

TOF vs non-TOF: variance reduction in a uniform cylinder

TOF vs non-TOF: variance reduction in a uniform cylinder

RAM-efficient OSEM with disk-backed TOF sinograms

RAM-efficient OSEM with disk-backed TOF sinograms

Listmode MLEM, OSEM, and SVRG

Listmode MLEM, OSEM, and SVRG

Convergence comparison: SGD vs SVRG with regularization (sinogram and listmode)

Convergence comparison: SGD vs SVRG with regularization (sinogram and listmode)

PDHG and LM-SPDHG to optimize the Poisson logL and total variation

PDHG and LM-SPDHG to optimize the Poisson logL and total variation

Joint activity and attenuation reconstruction (MLAA) for TOF PET

Joint activity and attenuation reconstruction (MLAA) for TOF PET

init method

Parameters:

operators (Sequence[LinearOperator]) – Sequence of linear operators

Examples

Detector mashing: fewer, bigger virtual detectors

Detector mashing: fewer, bigger virtual detectors

TOF-bin mashing: fewer, wider time-of-flight bins

TOF-bin mashing: fewer, wider time-of-flight bins

PET non-TOF sinogram projector

PET non-TOF sinogram projector

PET TOF sinogram projector

PET TOF sinogram projector

PET listmode projector (non-TOF and TOF)

PET listmode projector (non-TOF and TOF)

Convergence comparison: MLEM vs OSEM vs SVRG

Convergence comparison: MLEM vs OSEM vs SVRG

Convergence comparison: SGD vs SVRG with logcosh regularization

Convergence comparison: SGD vs SVRG with logcosh regularization

PDHG and SPDHG for PET reconstruction with a directional TV prior

PDHG and SPDHG for PET reconstruction with a directional TV prior

TOF vs non-TOF: variance reduction in a uniform cylinder

TOF vs non-TOF: variance reduction in a uniform cylinder

RAM-efficient OSEM with disk-backed TOF sinograms

RAM-efficient OSEM with disk-backed TOF sinograms

Listmode MLEM, OSEM, and SVRG

Listmode MLEM, OSEM, and SVRG

Convergence comparison: SGD vs SVRG with regularization (sinogram and listmode)

Convergence comparison: SGD vs SVRG with regularization (sinogram and listmode)

PDHG and LM-SPDHG to optimize the Poisson logL and total variation

PDHG and LM-SPDHG to optimize the Poisson logL and total variation

Joint activity and attenuation reconstruction (MLAA) for TOF PET

Joint activity and attenuation reconstruction (MLAA) for TOF PET
property H: AdjointLinearOperator

adjoint operator \(A^H\)

__call__(x: Array) Array

alias to apply(x)

Examples

Parameters:

x (Array)

Return type:

Array

__getitem__(i: int) LinearOperator[source]

get the i-th operator \(A_i\)

Examples

Parameters:

i (int)

Return type:

LinearOperator

adjoint(y: Array) Array

(scaled) adjoint step \(x = \overline{\alpha} A^H y\)

Parameters:

y (Array)

Return type:

Array

Examples

PET non-TOF sinogram projector

PET non-TOF sinogram projector

PET TOF sinogram projector

PET TOF sinogram projector

PET listmode projector (non-TOF and TOF)

PET listmode projector (non-TOF and TOF)

Convergence comparison: MLEM vs OSEM vs SVRG

Convergence comparison: MLEM vs OSEM vs SVRG

Convergence comparison: SGD vs SVRG with logcosh regularization

Convergence comparison: SGD vs SVRG with logcosh regularization

PDHG and SPDHG for PET reconstruction with a directional TV prior

PDHG and SPDHG for PET reconstruction with a directional TV prior

TOF vs non-TOF: variance reduction in a uniform cylinder

TOF vs non-TOF: variance reduction in a uniform cylinder

RAM-efficient OSEM with disk-backed TOF sinograms

RAM-efficient OSEM with disk-backed TOF sinograms

Listmode MLEM, OSEM, and SVRG

Listmode MLEM, OSEM, and SVRG

Convergence comparison: SGD vs SVRG with regularization (sinogram and listmode)

Convergence comparison: SGD vs SVRG with regularization (sinogram and listmode)
adjointness_test(xp: ModuleType | None = None, dev: str | None = None, verbose: bool = False, iscomplex: bool = False, dtype: type | None = None, **kwargs) bool

test whether the adjoint is correctly implemented

Parameters:
  • xp (ModuleType, optional) – array module to use. Defaults to the operator’s own namespace (self.xp) when it exposes one; otherwise must be given.

  • dev (str, optional) – device (cpu or cuda). Defaults to the operator’s own device (self.dev) when it exposes one, else the default device.

  • verbose (bool, optional) – verbose output

  • iscomplex (bool, optional) – use complex arrays

  • dtype (type | None, optional) – data type of the arrays

  • **kwargs (dict) – passed to np.isclose

Returns:

whether the adjoint is correctly implemented

Return type:

bool

Examples

apply(x: Array) Array

(scaled) forward step \(y = \alpha A x\)

Parameters:

x (Array)

Return type:

Array

Examples

property in_shape: tuple[int, ...]

Input shape of the innermost (last) operator.

norm(xp: ModuleType | None = None, dev: str | None = None, num_iter: int = 30, iscomplex: bool = False, verbose: bool = False) float

estimate norm of the linear operator using power iterations

Parameters:
  • xp (ModuleType, optional) – array module to use. Defaults to the operator’s own namespace (self.xp) when it exposes one; otherwise must be given.

  • dev (str, optional) – device (cpu or cuda). Defaults to the operator’s own device (self.dev) when it exposes one, else the default device.

  • num_iter (int, optional) – number of power iterations

  • iscomplex (bool, optional) – use complex arrays

  • verbose (bool, optional) – verbose output

Returns:

the norm of the linear operator

Return type:

float

Examples

PDHG and SPDHG for PET reconstruction with a directional TV prior

PDHG and SPDHG for PET reconstruction with a directional TV prior
property operators: Sequence[LinearOperator]

tuple of linear operators

property out_shape: tuple[int, ...]

Output shape of the outermost (first) operator.

property scale: float | complex

scalar factor applied to the linear operator

class parallelproj.operators.ElementwiseMultiplicationOperator(values: Array)[source]

Bases: LinearOperator

Element-wise multiplication operator (multiplication with a diagonal matrix)

Examples

PET non-TOF sinogram projector

PET non-TOF sinogram projector

PET TOF sinogram projector

PET TOF sinogram projector

PET listmode projector (non-TOF and TOF)

PET listmode projector (non-TOF and TOF)

Convergence comparison: MLEM vs OSEM vs SVRG

Convergence comparison: MLEM vs OSEM vs SVRG

Convergence comparison: SGD vs SVRG with logcosh regularization

Convergence comparison: SGD vs SVRG with logcosh regularization

PDHG and SPDHG for PET reconstruction with a directional TV prior

PDHG and SPDHG for PET reconstruction with a directional TV prior

TOF vs non-TOF: variance reduction in a uniform cylinder

TOF vs non-TOF: variance reduction in a uniform cylinder

RAM-efficient OSEM with disk-backed TOF sinograms

RAM-efficient OSEM with disk-backed TOF sinograms

Listmode MLEM, OSEM, and SVRG

Listmode MLEM, OSEM, and SVRG

Convergence comparison: SGD vs SVRG with regularization (sinogram and listmode)

Convergence comparison: SGD vs SVRG with regularization (sinogram and listmode)

PDHG and LM-SPDHG to optimize the Poisson logL and total variation

PDHG and LM-SPDHG to optimize the Poisson logL and total variation

init method

Parameters:

values (Array) – values of the diagonal matrix

Examples

PET non-TOF sinogram projector

PET non-TOF sinogram projector

PET TOF sinogram projector

PET TOF sinogram projector

PET listmode projector (non-TOF and TOF)

PET listmode projector (non-TOF and TOF)

Convergence comparison: MLEM vs OSEM vs SVRG

Convergence comparison: MLEM vs OSEM vs SVRG

Convergence comparison: SGD vs SVRG with logcosh regularization

Convergence comparison: SGD vs SVRG with logcosh regularization

PDHG and SPDHG for PET reconstruction with a directional TV prior

PDHG and SPDHG for PET reconstruction with a directional TV prior

TOF vs non-TOF: variance reduction in a uniform cylinder

TOF vs non-TOF: variance reduction in a uniform cylinder

RAM-efficient OSEM with disk-backed TOF sinograms

RAM-efficient OSEM with disk-backed TOF sinograms

Listmode MLEM, OSEM, and SVRG

Listmode MLEM, OSEM, and SVRG

Convergence comparison: SGD vs SVRG with regularization (sinogram and listmode)

Convergence comparison: SGD vs SVRG with regularization (sinogram and listmode)

PDHG and LM-SPDHG to optimize the Poisson logL and total variation

PDHG and LM-SPDHG to optimize the Poisson logL and total variation
property H: AdjointLinearOperator

adjoint operator \(A^H\)

__call__(x: Array) Array

alias to apply(x)

Examples

Parameters:

x (Array)

Return type:

Array

adjoint(y: Array) Array

(scaled) adjoint step \(x = \overline{\alpha} A^H y\)

Parameters:

y (Array)

Return type:

Array

Examples

adjointness_test(xp: ModuleType | None = None, dev: str | None = None, verbose: bool = False, iscomplex: bool = False, dtype: type | None = None, **kwargs) bool

test whether the adjoint is correctly implemented

Parameters:
  • xp (ModuleType, optional) – array module to use. Defaults to the operator’s own namespace (self.xp) when it exposes one; otherwise must be given.

  • dev (str, optional) – device (cpu or cuda). Defaults to the operator’s own device (self.dev) when it exposes one, else the default device.

  • verbose (bool, optional) – verbose output

  • iscomplex (bool, optional) – use complex arrays

  • dtype (type | None, optional) – data type of the arrays

  • **kwargs (dict) – passed to np.isclose

Returns:

whether the adjoint is correctly implemented

Return type:

bool

Examples

apply(x: Array) Array

(scaled) forward step \(y = \alpha A x\)

Parameters:

x (Array)

Return type:

Array

Examples

property in_shape: tuple[int, ...]

Shape of the diagonal values array (operator is square).

property iscomplex: bool

bool whether the operator is complex

norm(xp: ModuleType | None = None, dev: str | None = None, num_iter: int = 30, iscomplex: bool = False, verbose: bool = False) float

estimate norm of the linear operator using power iterations

Parameters:
  • xp (ModuleType, optional) – array module to use. Defaults to the operator’s own namespace (self.xp) when it exposes one; otherwise must be given.

  • dev (str, optional) – device (cpu or cuda). Defaults to the operator’s own device (self.dev) when it exposes one, else the default device.

  • num_iter (int, optional) – number of power iterations

  • iscomplex (bool, optional) – use complex arrays

  • verbose (bool, optional) – verbose output

Returns:

the norm of the linear operator

Return type:

float

Examples

property out_shape: tuple[int, ...]

Shape of the diagonal values array (operator is square).

property scale: float | complex

scalar factor applied to the linear operator

property values: Array

values that get multiplied

property xp: ModuleType

array module of the operator

class parallelproj.operators.FiniteForwardDifference(in_shape: tuple[int, ...])[source]

Bases: LinearOperator

Forward finite-difference gradient operator for 1-D to 4-D images.

Maps an image of shape in_shape to a gradient field of shape (ndim, *in_shape) where axis 0 enumerates the spatial directions. At each boundary the difference wraps to zero: the last difference along each axis is forced to zero in the forward pass (as if the image is padded with a copy of the border value, so the difference there vanishes). The adjoint is the negative discrete divergence, consistent with the standard TV regularisation convention. Self-adjointness is verified by adjointness_test().

Examples

Convergence comparison: SGD vs SVRG with logcosh regularization

Convergence comparison: SGD vs SVRG with logcosh regularization

PDHG and SPDHG for PET reconstruction with a directional TV prior

PDHG and SPDHG for PET reconstruction with a directional TV prior

Convergence comparison: SGD vs SVRG with regularization (sinogram and listmode)

Convergence comparison: SGD vs SVRG with regularization (sinogram and listmode)

PDHG and LM-SPDHG to optimize the Poisson logL and total variation

PDHG and LM-SPDHG to optimize the Poisson logL and total variation

Penalised transmission reconstruction (MAPTR) with an edge-preserving prior

Penalised transmission reconstruction (MAPTR) with an edge-preserving prior

Joint activity and attenuation reconstruction (MLAA) for TOF PET

Joint activity and attenuation reconstruction (MLAA) for TOF PET
Parameters:

in_shape (tuple[int, ...]) – Shape of the input image. Must have 1 to 4 dimensions; raises ValueError for higher-dimensional inputs.

Examples

Convergence comparison: SGD vs SVRG with logcosh regularization

Convergence comparison: SGD vs SVRG with logcosh regularization

PDHG and SPDHG for PET reconstruction with a directional TV prior

PDHG and SPDHG for PET reconstruction with a directional TV prior

Convergence comparison: SGD vs SVRG with regularization (sinogram and listmode)

Convergence comparison: SGD vs SVRG with regularization (sinogram and listmode)

PDHG and LM-SPDHG to optimize the Poisson logL and total variation

PDHG and LM-SPDHG to optimize the Poisson logL and total variation

Penalised transmission reconstruction (MAPTR) with an edge-preserving prior

Penalised transmission reconstruction (MAPTR) with an edge-preserving prior

Joint activity and attenuation reconstruction (MLAA) for TOF PET

Joint activity and attenuation reconstruction (MLAA) for TOF PET
property H: AdjointLinearOperator

adjoint operator \(A^H\)

__call__(x: Array) Array

alias to apply(x)

Examples

Parameters:

x (Array)

Return type:

Array

adjoint(y: Array) Array

(scaled) adjoint step \(x = \overline{\alpha} A^H y\)

Parameters:

y (Array)

Return type:

Array

Examples

adjointness_test(xp: ModuleType | None = None, dev: str | None = None, verbose: bool = False, iscomplex: bool = False, dtype: type | None = None, **kwargs) bool

test whether the adjoint is correctly implemented

Parameters:
  • xp (ModuleType, optional) – array module to use. Defaults to the operator’s own namespace (self.xp) when it exposes one; otherwise must be given.

  • dev (str, optional) – device (cpu or cuda). Defaults to the operator’s own device (self.dev) when it exposes one, else the default device.

  • verbose (bool, optional) – verbose output

  • iscomplex (bool, optional) – use complex arrays

  • dtype (type | None, optional) – data type of the arrays

  • **kwargs (dict) – passed to np.isclose

Returns:

whether the adjoint is correctly implemented

Return type:

bool

Examples

apply(x: Array) Array

(scaled) forward step \(y = \alpha A x\)

Parameters:

x (Array)

Return type:

Array

Examples

property in_shape: tuple[int, ...]

shape of the input array

property ndim: int

number of dimensions of the input array

norm(xp: ModuleType | None = None, dev: str | None = None, num_iter: int = 30, iscomplex: bool = False, verbose: bool = False) float

estimate norm of the linear operator using power iterations

Parameters:
  • xp (ModuleType, optional) – array module to use. Defaults to the operator’s own namespace (self.xp) when it exposes one; otherwise must be given.

  • dev (str, optional) – device (cpu or cuda). Defaults to the operator’s own device (self.dev) when it exposes one, else the default device.

  • num_iter (int, optional) – number of power iterations

  • iscomplex (bool, optional) – use complex arrays

  • verbose (bool, optional) – verbose output

Returns:

the norm of the linear operator

Return type:

float

Examples

property out_shape: tuple[int, ...]

shape of the output array

property scale: float | complex

scalar factor applied to the linear operator

class parallelproj.operators.GaussianFilterOperator(in_shape: tuple[int, ...], **kwargs)[source]

Bases: LinearOperator

Isotropic Gaussian smoothing operator (self-adjoint).

Works with NumPy, CuPy, and PyTorch (CPU and CUDA) arrays. GPU arrays (CuPy, and PyTorch CUDA round-tripped through CuPy via DLPack) are filtered with cupyx.scipy.ndimage.gaussian_filter; CPU arrays use scipy.ndimage.gaussian_filter. Routing the GPU path through cupyx makes it independent of scipy’s array-API delegation, so it works regardless of the SCIPY_ARRAY_API env var or import order. All keyword arguments accepted by gaussian_filter (e.g. sigma, mode, truncate) are forwarded through **kwargs. Because the Gaussian kernel is symmetric, the adjoint equals the forward application.

Examples

PET non-TOF sinogram projector

PET non-TOF sinogram projector

PET TOF sinogram projector

PET TOF sinogram projector

PET listmode projector (non-TOF and TOF)

PET listmode projector (non-TOF and TOF)

Convergence comparison: MLEM vs OSEM vs SVRG

Convergence comparison: MLEM vs OSEM vs SVRG

Convergence comparison: SGD vs SVRG with logcosh regularization

Convergence comparison: SGD vs SVRG with logcosh regularization

PDHG and SPDHG for PET reconstruction with a directional TV prior

PDHG and SPDHG for PET reconstruction with a directional TV prior

TOF vs non-TOF: variance reduction in a uniform cylinder

TOF vs non-TOF: variance reduction in a uniform cylinder

RAM-efficient OSEM with disk-backed TOF sinograms

RAM-efficient OSEM with disk-backed TOF sinograms

Exact vs. “safe epsilon” mode of the negative Poisson log-likelihood

Exact vs. "safe epsilon" mode of the negative Poisson log-likelihood

Listmode MLEM, OSEM, and SVRG

Listmode MLEM, OSEM, and SVRG

Convergence comparison: SGD vs SVRG with regularization (sinogram and listmode)

Convergence comparison: SGD vs SVRG with regularization (sinogram and listmode)

PDHG and LM-SPDHG to optimize the Poisson logL and total variation

PDHG and LM-SPDHG to optimize the Poisson logL and total variation

Joint activity and attenuation reconstruction (MLAA) for TOF PET

Joint activity and attenuation reconstruction (MLAA) for TOF PET

init method

Parameters:
  • in_shape (tuple[int, ...]) – shape of the input array

  • **kwargs (dict) – passed to scipy.ndimage.gaussian_filter; most commonly sigma (standard deviation in pixels), plus optional mode, truncate, etc.

Examples

PET non-TOF sinogram projector

PET non-TOF sinogram projector

PET TOF sinogram projector

PET TOF sinogram projector

PET listmode projector (non-TOF and TOF)

PET listmode projector (non-TOF and TOF)

Convergence comparison: MLEM vs OSEM vs SVRG

Convergence comparison: MLEM vs OSEM vs SVRG

Convergence comparison: SGD vs SVRG with logcosh regularization

Convergence comparison: SGD vs SVRG with logcosh regularization

PDHG and SPDHG for PET reconstruction with a directional TV prior

PDHG and SPDHG for PET reconstruction with a directional TV prior

TOF vs non-TOF: variance reduction in a uniform cylinder

TOF vs non-TOF: variance reduction in a uniform cylinder

RAM-efficient OSEM with disk-backed TOF sinograms

RAM-efficient OSEM with disk-backed TOF sinograms

Exact vs. “safe epsilon” mode of the negative Poisson log-likelihood

Exact vs. "safe epsilon" mode of the negative Poisson log-likelihood

Listmode MLEM, OSEM, and SVRG

Listmode MLEM, OSEM, and SVRG

Convergence comparison: SGD vs SVRG with regularization (sinogram and listmode)

Convergence comparison: SGD vs SVRG with regularization (sinogram and listmode)

PDHG and LM-SPDHG to optimize the Poisson logL and total variation

PDHG and LM-SPDHG to optimize the Poisson logL and total variation

Joint activity and attenuation reconstruction (MLAA) for TOF PET

Joint activity and attenuation reconstruction (MLAA) for TOF PET
property H: AdjointLinearOperator

adjoint operator \(A^H\)

__call__(x: Array) Array

alias to apply(x)

Examples

Parameters:

x (Array)

Return type:

Array

adjoint(y: Array) Array

(scaled) adjoint step \(x = \overline{\alpha} A^H y\)

Parameters:

y (Array)

Return type:

Array

Examples

Exact vs. “safe epsilon” mode of the negative Poisson log-likelihood

Exact vs. "safe epsilon" mode of the negative Poisson log-likelihood
adjointness_test(xp: ModuleType | None = None, dev: str | None = None, verbose: bool = False, iscomplex: bool = False, dtype: type | None = None, **kwargs) bool

test whether the adjoint is correctly implemented

Parameters:
  • xp (ModuleType, optional) – array module to use. Defaults to the operator’s own namespace (self.xp) when it exposes one; otherwise must be given.

  • dev (str, optional) – device (cpu or cuda). Defaults to the operator’s own device (self.dev) when it exposes one, else the default device.

  • verbose (bool, optional) – verbose output

  • iscomplex (bool, optional) – use complex arrays

  • dtype (type | None, optional) – data type of the arrays

  • **kwargs (dict) – passed to np.isclose

Returns:

whether the adjoint is correctly implemented

Return type:

bool

Examples

apply(x: Array) Array

(scaled) forward step \(y = \alpha A x\)

Parameters:

x (Array)

Return type:

Array

Examples

property in_shape: tuple[int, ...]

Shape of the input (and output) array (operator is square).

norm(xp: ModuleType | None = None, dev: str | None = None, num_iter: int = 30, iscomplex: bool = False, verbose: bool = False) float

estimate norm of the linear operator using power iterations

Parameters:
  • xp (ModuleType, optional) – array module to use. Defaults to the operator’s own namespace (self.xp) when it exposes one; otherwise must be given.

  • dev (str, optional) – device (cpu or cuda). Defaults to the operator’s own device (self.dev) when it exposes one, else the default device.

  • num_iter (int, optional) – number of power iterations

  • iscomplex (bool, optional) – use complex arrays

  • verbose (bool, optional) – verbose output

Returns:

the norm of the linear operator

Return type:

float

Examples

property out_shape: tuple[int, ...]

Shape of the output (and input) array (operator is square).

property scale: float | complex

scalar factor applied to the linear operator

class parallelproj.operators.GradientFieldProjectionOperator(gradient_field: Array, eta: float = 0.0)[source]

Bases: LinearOperator

Gradient field projection operator (self-adjoint).

Projects a gradient field onto the subspace orthogonal to a normalised structural prior gradient \(\xi_n\):

\[P_{\xi_n}x = x - \langle \xi_n, x \rangle \xi_n, \qquad \xi_n = g_n / \| g_n \|_{\eta}\]

where \(g_n\) is the joint gradient field and \(\eta\) is a smoothing parameter for the pointwise gradient norm. The operator is self-adjoint (its own adjoint) because orthogonal projection operators are symmetric.

See Ehrhardt and Betcke, “Multicontrast MRI Reconstruction with Structure-Guided Total Variation” (doi: 10.1137/15M1047325).

Examples

PDHG and SPDHG for PET reconstruction with a directional TV prior

PDHG and SPDHG for PET reconstruction with a directional TV prior
Parameters:
  • gradient_field (Array) – a real gradient field. In 3D, the shape would be [3,n0,n1,n2]. In 2D, the shape would be [2,n0,n1]. This can be e.g. the output of the FiniteForwardDifference operator applied to a structural prior image.

  • eta (float, optional) – smoothing parameter used in the pointwise gradient norm default 0.0

Examples

PDHG and SPDHG for PET reconstruction with a directional TV prior

PDHG and SPDHG for PET reconstruction with a directional TV prior
property H: AdjointLinearOperator

adjoint operator \(A^H\)

__call__(x: Array) Array

alias to apply(x)

Examples

Parameters:

x (Array)

Return type:

Array

adjoint(y: Array) Array

(scaled) adjoint step \(x = \overline{\alpha} A^H y\)

Parameters:

y (Array)

Return type:

Array

Examples

adjointness_test(xp: ModuleType | None = None, dev: str | None = None, verbose: bool = False, iscomplex: bool = False, dtype: type | None = None, **kwargs) bool

test whether the adjoint is correctly implemented

Parameters:
  • xp (ModuleType, optional) – array module to use. Defaults to the operator’s own namespace (self.xp) when it exposes one; otherwise must be given.

  • dev (str, optional) – device (cpu or cuda). Defaults to the operator’s own device (self.dev) when it exposes one, else the default device.

  • verbose (bool, optional) – verbose output

  • iscomplex (bool, optional) – use complex arrays

  • dtype (type | None, optional) – data type of the arrays

  • **kwargs (dict) – passed to np.isclose

Returns:

whether the adjoint is correctly implemented

Return type:

bool

Examples

apply(x: Array) Array

(scaled) forward step \(y = \alpha A x\)

Parameters:

x (Array)

Return type:

Array

Examples

property dev: str

device of the operator

property eta: float

smoothing parameter

property in_shape: tuple[int, ...]

Shape of the gradient field (ndim, *spatial_shape).

norm(xp: ModuleType | None = None, dev: str | None = None, num_iter: int = 30, iscomplex: bool = False, verbose: bool = False) float

estimate norm of the linear operator using power iterations

Parameters:
  • xp (ModuleType, optional) – array module to use. Defaults to the operator’s own namespace (self.xp) when it exposes one; otherwise must be given.

  • dev (str, optional) – device (cpu or cuda). Defaults to the operator’s own device (self.dev) when it exposes one, else the default device.

  • num_iter (int, optional) – number of power iterations

  • iscomplex (bool, optional) – use complex arrays

  • verbose (bool, optional) – verbose output

Returns:

the norm of the linear operator

Return type:

float

Examples

property normalized_gradient_field: Array

normalized gradient field

property out_shape: tuple[int, ...]

Shape of the gradient field (ndim, *spatial_shape) (same as in_shape).

property scale: float | complex

scalar factor applied to the linear operator

property xp: ModuleType

array module of the operator

class parallelproj.operators.LinearOperator[source]

Bases: ABC

Abstract base class for array-API-compatible linear operators.

Subclasses implement _apply() (\(y = Ax\)) and _adjoint() (\(x = A^H y\)). The public apply() and adjoint() methods apply an optional scalar scale factor (\(\alpha A\) and \(\overline{\alpha} A^H\)). Utility methods adjointness_test() and norm() are provided for validation and step-size estimation.

Examples

Michelograms and axial sinogram compression

Michelograms and axial sinogram compression

Detector mashing: fewer, bigger virtual detectors

Detector mashing: fewer, bigger virtual detectors

TOF-bin mashing: fewer, wider time-of-flight bins

TOF-bin mashing: fewer, wider time-of-flight bins

PET non-TOF sinogram projector

PET non-TOF sinogram projector

PET TOF sinogram projector

PET TOF sinogram projector

Non-TOF and TOF projections using a modularized (block) PET scanner geometry

Non-TOF and TOF projections using a modularized (block) PET scanner geometry

PET listmode projector (non-TOF and TOF)

PET listmode projector (non-TOF and TOF)

Listmode to sinogram unlisting

Listmode to sinogram unlisting

Convergence comparison: MLEM vs OSEM vs SVRG

Convergence comparison: MLEM vs OSEM vs SVRG

Convergence comparison: SGD vs SVRG with logcosh regularization

Convergence comparison: SGD vs SVRG with logcosh regularization

PDHG and SPDHG for PET reconstruction with a directional TV prior

PDHG and SPDHG for PET reconstruction with a directional TV prior

2D non-TOF filtered back projection (FBP) of Poisson data

2D non-TOF filtered back projection (FBP) of Poisson data

DePierro’s algorithm to optimize the Poisson logL with quadratic intensity prior

DePierro's algorithm to optimize the Poisson logL with quadratic intensity prior

TOF vs non-TOF: variance reduction in a uniform cylinder

TOF vs non-TOF: variance reduction in a uniform cylinder

RAM-efficient OSEM with disk-backed TOF sinograms

RAM-efficient OSEM with disk-backed TOF sinograms

Exact vs. “safe epsilon” mode of the negative Poisson log-likelihood

Exact vs. "safe epsilon" mode of the negative Poisson log-likelihood

Listmode MLEM, OSEM, and SVRG

Listmode MLEM, OSEM, and SVRG

Convergence comparison: SGD vs SVRG with regularization (sinogram and listmode)

Convergence comparison: SGD vs SVRG with regularization (sinogram and listmode)

Penalised transmission reconstruction (MAPTR) with an edge-preserving prior

Penalised transmission reconstruction (MAPTR) with an edge-preserving prior

pytorch parallelproj projection layer

pytorch parallelproj projection layer
property H: AdjointLinearOperator

adjoint operator \(A^H\)

__call__(x: Array) Array[source]

alias to apply(x)

Examples

Parameters:

x (Array)

Return type:

Array

adjoint(y: Array) Array[source]

(scaled) adjoint step \(x = \overline{\alpha} A^H y\)

Parameters:

y (Array)

Return type:

Array

Examples

Michelograms and axial sinogram compression

Michelograms and axial sinogram compression

Detector mashing: fewer, bigger virtual detectors

Detector mashing: fewer, bigger virtual detectors

TOF-bin mashing: fewer, wider time-of-flight bins

TOF-bin mashing: fewer, wider time-of-flight bins

PET non-TOF sinogram projector

PET non-TOF sinogram projector

PET TOF sinogram projector

PET TOF sinogram projector

Non-TOF and TOF projections using a modularized (block) PET scanner geometry

Non-TOF and TOF projections using a modularized (block) PET scanner geometry

PET listmode projector (non-TOF and TOF)

PET listmode projector (non-TOF and TOF)

Convergence comparison: MLEM vs OSEM vs SVRG

Convergence comparison: MLEM vs OSEM vs SVRG

Convergence comparison: SGD vs SVRG with logcosh regularization

Convergence comparison: SGD vs SVRG with logcosh regularization

PDHG and SPDHG for PET reconstruction with a directional TV prior

PDHG and SPDHG for PET reconstruction with a directional TV prior

2D non-TOF filtered back projection (FBP) of Poisson data

2D non-TOF filtered back projection (FBP) of Poisson data

DePierro’s algorithm to optimize the Poisson logL with quadratic intensity prior

DePierro's algorithm to optimize the Poisson logL with quadratic intensity prior

TOF vs non-TOF: variance reduction in a uniform cylinder

TOF vs non-TOF: variance reduction in a uniform cylinder

RAM-efficient OSEM with disk-backed TOF sinograms

RAM-efficient OSEM with disk-backed TOF sinograms

Exact vs. “safe epsilon” mode of the negative Poisson log-likelihood

Exact vs. "safe epsilon" mode of the negative Poisson log-likelihood

Listmode MLEM, OSEM, and SVRG

Listmode MLEM, OSEM, and SVRG

Convergence comparison: SGD vs SVRG with regularization (sinogram and listmode)

Convergence comparison: SGD vs SVRG with regularization (sinogram and listmode)

Penalised transmission reconstruction (MAPTR) with an edge-preserving prior

Penalised transmission reconstruction (MAPTR) with an edge-preserving prior
adjointness_test(xp: ModuleType | None = None, dev: str | None = None, verbose: bool = False, iscomplex: bool = False, dtype: type | None = None, **kwargs) bool[source]

test whether the adjoint is correctly implemented

Parameters:
  • xp (ModuleType, optional) – array module to use. Defaults to the operator’s own namespace (self.xp) when it exposes one; otherwise must be given.

  • dev (str, optional) – device (cpu or cuda). Defaults to the operator’s own device (self.dev) when it exposes one, else the default device.

  • verbose (bool, optional) – verbose output

  • iscomplex (bool, optional) – use complex arrays

  • dtype (type | None, optional) – data type of the arrays

  • **kwargs (dict) – passed to np.isclose

Returns:

whether the adjoint is correctly implemented

Return type:

bool

Examples

TOF-bin mashing: fewer, wider time-of-flight bins

TOF-bin mashing: fewer, wider time-of-flight bins

Non-TOF and TOF projections using a modularized (block) PET scanner geometry

Non-TOF and TOF projections using a modularized (block) PET scanner geometry
apply(x: Array) Array[source]

(scaled) forward step \(y = \alpha A x\)

Parameters:

x (Array)

Return type:

Array

Examples

abstract property in_shape: tuple[int, ...]

shape of the input array

norm(xp: ModuleType | None = None, dev: str | None = None, num_iter: int = 30, iscomplex: bool = False, verbose: bool = False) float[source]

estimate norm of the linear operator using power iterations

Parameters:
  • xp (ModuleType, optional) – array module to use. Defaults to the operator’s own namespace (self.xp) when it exposes one; otherwise must be given.

  • dev (str, optional) – device (cpu or cuda). Defaults to the operator’s own device (self.dev) when it exposes one, else the default device.

  • num_iter (int, optional) – number of power iterations

  • iscomplex (bool, optional) – use complex arrays

  • verbose (bool, optional) – verbose output

Returns:

the norm of the linear operator

Return type:

float

Examples

TOF-bin mashing: fewer, wider time-of-flight bins

TOF-bin mashing: fewer, wider time-of-flight bins

PDHG and SPDHG for PET reconstruction with a directional TV prior

PDHG and SPDHG for PET reconstruction with a directional TV prior
abstract property out_shape: tuple[int, ...]

shape of the output array

property scale: float | complex

scalar factor applied to the linear operator

class parallelproj.operators.LinearOperatorSequence(operators: Sequence[LinearOperator])[source]

Bases: Sequence[LinearOperator]

Sequence of linear operators

\[A^0, A^1 \ldots, A^{n-1}\]

that can be evaluated independently.

Examples

Convergence comparison: MLEM vs OSEM vs SVRG

Convergence comparison: MLEM vs OSEM vs SVRG

Convergence comparison: SGD vs SVRG with logcosh regularization

Convergence comparison: SGD vs SVRG with logcosh regularization

PDHG and SPDHG for PET reconstruction with a directional TV prior

PDHG and SPDHG for PET reconstruction with a directional TV prior

RAM-efficient OSEM with disk-backed TOF sinograms

RAM-efficient OSEM with disk-backed TOF sinograms

PDHG and LM-SPDHG to optimize the Poisson logL and total variation

PDHG and LM-SPDHG to optimize the Poisson logL and total variation

init method

Parameters:

operators (Sequence[LinearOperator]) – Sequence of linear operators

Examples

Convergence comparison: MLEM vs OSEM vs SVRG

Convergence comparison: MLEM vs OSEM vs SVRG

Convergence comparison: SGD vs SVRG with logcosh regularization

Convergence comparison: SGD vs SVRG with logcosh regularization

PDHG and SPDHG for PET reconstruction with a directional TV prior

PDHG and SPDHG for PET reconstruction with a directional TV prior

RAM-efficient OSEM with disk-backed TOF sinograms

RAM-efficient OSEM with disk-backed TOF sinograms

PDHG and LM-SPDHG to optimize the Poisson logL and total variation

PDHG and LM-SPDHG to optimize the Poisson logL and total variation
__call__(x: Array) list[Array][source]

Alias for apply().

Examples

Parameters:

x (Array)

Return type:

list[Array]

__getitem__(i: int) LinearOperator[source]

get the i-th linear operator \(A^i\)

Examples

Parameters:

i (int)

Return type:

LinearOperator

adjoint(y: list[Array]) Array[source]

Sum of adjoint outputs: \(\sum_i (A^i)^H y^i\).

Parameters:

y (list[Array]) – List of n arrays, one per operator, each matching the corresponding operator’s out_shape.

Returns:

Sum of all adjoint outputs, shape in_shape.

Return type:

Array

Examples

apply(x: Array) list[Array][source]

Apply each operator independently: \((A^0(x), A^1(x), \ldots, A^{n-1}(x))\).

Parameters:

x (Array) – Input array of shape in_shape.

Returns:

List of n output arrays, one per operator.

Return type:

list[Array]

Examples

count(value) integer -- return number of occurrences of value

Examples

property in_shape: tuple[int, ...]

shape of the input array

index(value[, start[, stop]]) integer -- return first index of value.

Raises ValueError if the value is not present.

Supporting start and stop arguments is optional, but recommended.

Examples

norms(xp: ModuleType, dev: str) list[float][source]

\(\text{norm}(A^i)\) for all \(i\)

Parameters:
  • xp (ModuleType) – array module to use

  • dev (str) – device (cpu or cuda)

Returns:

norm of each operator in the sequence

Return type:

list[float]

Examples

property operators: Sequence[LinearOperator]

all subset operators

property out_shapes: list[tuple[int, ...]]

shapes of the output array of all subset operators

class parallelproj.operators.MatrixOperator(A: Array)[source]

Bases: LinearOperator

Linear Operator defined by dense matrix multiplication

Examples

DePierro’s algorithm to optimize the Poisson logL with quadratic intensity prior

DePierro's algorithm to optimize the Poisson logL with quadratic intensity prior

init method

Parameters:

A (Array) – 2D real or complex array representing the matrix

Examples

DePierro’s algorithm to optimize the Poisson logL with quadratic intensity prior

DePierro's algorithm to optimize the Poisson logL with quadratic intensity prior
property A: Array

matrix of the operator

property H: AdjointLinearOperator

adjoint operator \(A^H\)

__call__(x: Array) Array

alias to apply(x)

Examples

Parameters:

x (Array)

Return type:

Array

adjoint(y: Array) Array

(scaled) adjoint step \(x = \overline{\alpha} A^H y\)

Parameters:

y (Array)

Return type:

Array

Examples

DePierro’s algorithm to optimize the Poisson logL with quadratic intensity prior

DePierro's algorithm to optimize the Poisson logL with quadratic intensity prior
adjointness_test(xp: ModuleType | None = None, dev: str | None = None, verbose: bool = False, iscomplex: bool = False, dtype: type | None = None, **kwargs) bool

test whether the adjoint is correctly implemented

Parameters:
  • xp (ModuleType, optional) – array module to use. Defaults to the operator’s own namespace (self.xp) when it exposes one; otherwise must be given.

  • dev (str, optional) – device (cpu or cuda). Defaults to the operator’s own device (self.dev) when it exposes one, else the default device.

  • verbose (bool, optional) – verbose output

  • iscomplex (bool, optional) – use complex arrays

  • dtype (type | None, optional) – data type of the arrays

  • **kwargs (dict) – passed to np.isclose

Returns:

whether the adjoint is correctly implemented

Return type:

bool

Examples

apply(x: Array) Array

(scaled) forward step \(y = \alpha A x\)

Parameters:

x (Array)

Return type:

Array

Examples

property in_shape: tuple[int, ...]

(ncols,) — number of columns of the matrix.

property iscomplex: bool

bool whether the operator is complex

norm(xp: ModuleType | None = None, dev: str | None = None, num_iter: int = 30, iscomplex: bool = False, verbose: bool = False) float

estimate norm of the linear operator using power iterations

Parameters:
  • xp (ModuleType, optional) – array module to use. Defaults to the operator’s own namespace (self.xp) when it exposes one; otherwise must be given.

  • dev (str, optional) – device (cpu or cuda). Defaults to the operator’s own device (self.dev) when it exposes one, else the default device.

  • num_iter (int, optional) – number of power iterations

  • iscomplex (bool, optional) – use complex arrays

  • verbose (bool, optional) – verbose output

Returns:

the norm of the linear operator

Return type:

float

Examples

property out_shape: tuple[int, ...]

(nrows,) — number of rows of the matrix.

property scale: float | complex

scalar factor applied to the linear operator

property xp: ModuleType

array module of the operator

class parallelproj.operators.VstackOperator(operators: tuple[LinearOperator, ...])[source]

Bases: LinearOperator

Stack multiple linear operators vertically into a single operator.

All operators must share the same in_shape. Each operator’s output is ravelled to a 1-D vector before concatenation, so out_shape is always (sum of all output sizes,) regardless of the individual output shapes. The adjoint sums the individual adjoint outputs over all stacked operators.

Examples

init method

Parameters:

operators (tuple[LinearOperator, ...]) – tuple of linear operators

Examples

property H: AdjointLinearOperator

adjoint operator \(A^H\)

__call__(x: Array) Array

alias to apply(x)

Examples

Parameters:

x (Array)

Return type:

Array

adjoint(y: Array) Array

(scaled) adjoint step \(x = \overline{\alpha} A^H y\)

Parameters:

y (Array)

Return type:

Array

Examples

adjointness_test(xp: ModuleType | None = None, dev: str | None = None, verbose: bool = False, iscomplex: bool = False, dtype: type | None = None, **kwargs) bool

test whether the adjoint is correctly implemented

Parameters:
  • xp (ModuleType, optional) – array module to use. Defaults to the operator’s own namespace (self.xp) when it exposes one; otherwise must be given.

  • dev (str, optional) – device (cpu or cuda). Defaults to the operator’s own device (self.dev) when it exposes one, else the default device.

  • verbose (bool, optional) – verbose output

  • iscomplex (bool, optional) – use complex arrays

  • dtype (type | None, optional) – data type of the arrays

  • **kwargs (dict) – passed to np.isclose

Returns:

whether the adjoint is correctly implemented

Return type:

bool

Examples

apply(x: Array) Array

(scaled) forward step \(y = \alpha A x\)

Parameters:

x (Array)

Return type:

Array

Examples

property in_shape: tuple[int, ...]

Common input shape shared by all stacked operators.

norm(xp: ModuleType | None = None, dev: str | None = None, num_iter: int = 30, iscomplex: bool = False, verbose: bool = False) float

estimate norm of the linear operator using power iterations

Parameters:
  • xp (ModuleType, optional) – array module to use. Defaults to the operator’s own namespace (self.xp) when it exposes one; otherwise must be given.

  • dev (str, optional) – device (cpu or cuda). Defaults to the operator’s own device (self.dev) when it exposes one, else the default device.

  • num_iter (int, optional) – number of power iterations

  • iscomplex (bool, optional) – use complex arrays

  • verbose (bool, optional) – verbose output

Returns:

the norm of the linear operator

Return type:

float

Examples

property out_shape: tuple[int, ...]

(N,) — total size of all operator outputs ravelled and concatenated.

property scale: float | complex

scalar factor applied to the linear operator