spyrit.core.meas.DynamicLinear
- class spyrit.core.meas.DynamicLinear(H: tensor, time_dim: int, meas_shape: int | Size | Iterable[int] = None, meas_dims: int | Size | Iterable[int] = None, img_shape: int | Size | Iterable[int] = None, *, noise_model: Module = Identity(), white_acq: tensor = None, dtype: dtype = torch.float32, device: device = device(type='cpu'))[source]
Bases:
LinearSimulates linear measurements of a moving scene
\[m = \mathcal{N}\left( \text{diag}(H x_{t=1, ..., M})\right),\]where \(H\in\mathbb{R}^{M \times N}\) is the acquisition matrix, \(x_{t=1, ..., M} \in \mathbb{R}^{N \times M}\) is the temporal signal of interest, \(M\) is both the number of measurements and the number of frames, \(N\) is the dimension of the signal within the field of view, \(\text{diag}\colon\, \mathbb{R}^{M \times M} \to \mathbb{R}^M\) extracts the diagonal of its input, and \(\mathcal{N} \colon\, \mathbb{R}^M \to \mathbb{R}^M\) represents a noise operator (e.g., Gaussian).
Warning
The current implementation only supports 2D spatial dimensions (i.e., images). Consequently, meas_shape and img_shape must be tuples of two integers.
Warning
For each call, there must be exactly as many frames in \(x\) as there are measurements in the linear operator used to initialize the class.
- Args:
H(torch.tensor): measurement matrix (linear operator) with shape \((M, N)\). Only real values are supported.time_dim(int): dimension index in the input tensor \(x\) that corresponds to time (i.e., the frames dimension).meas_shape(tuple, optional): Shape of the measurement patterns. Must be a tuple of two integers representing the height and width of the patterns. If not specified, the shape is suppposed to be a square image. If not, an error is raised. Defaults to None.meas_dims(tuple, optional): Dimensions of \(x_{t=1, ..., M}\) the acquisition matrix applies to. Must be a tuple with the same length asmeas_shape. If not, an error is raised. Defaults to the last dimensions of the multi-dimensional array \(x_{t=1, ..., M}\) (e.g., (-2,-1) when len(meas_shape)=2).img_shape(tuple, optional): Shape of the image. Must be a tuple of two integers representing the height and width of the image. If not specified, the shape is taken as equal to meas_shape. Setting this value is particularly useful when using an extended field of view [Maitre2024_2].noise_model(seespyrit.core.noise): Noise model \(\mathcal{N}\). Defaults to torch.nn.Identity().white_acq(torch.tensor, optional): Eventual spatial gain resulting from detector inhomogeneities and used for dynamic flat-field correction. It can be determined from a “white acquisition” without any object. If None, no correction is applied. Must haveself.meas_shapeshape.- Attributes:
M(int): Number of measurements.N(int): Number of pixels in the field of view.L(int): Number of pixels in the extended field of view.meas_shape(tuple): Shape of the underlying multi-dimensional array \(x\) over the field of view.img_shape(tuple): Shape of the underlying multi-dimensional array \(x\) over the extended field of view.H(torch.tensor): Static measurement matrix of shape \((M, N)\) initialized as \(H\).H_dyn(torch.tensor): Dynamic measurement matrix \(H_{\rm{dyn}}\) of shape. \((M, L)\). Must be set using the methodbuild_dynamic_forward()before being accessed.- Example:
>>> import torch >>> from spyrit.core.meas import DynamicLinear >>> >>> x = torch.rand([1, 400, 3, 50, 50]) # dummy RGB video with 400 frames of size 50x50 >>> H = torch.rand([400, 40*40]) # dummy static measurement matrix >>> meas_op = DynamicLinear(H, time_dim=1, meas_shape=(40, 40), img_shape=(50, 50)) >>> print(meas_op) DynamicLinear( (noise_model): Identity() )
- References:
[Maitre2024_2] Maitre, T., Bretin, E., Phan, R., Ducros, N., & Sdika, M. (2024, October). Dynamic single-pixel imaging on an extended field of view without warping the patterns. In International Conference on Medical Image Computing and Computer-Assisted Intervention (pp. 275-284). Cham: Springer Nature Switzerland. DOI: 10.1007/978-3-031-72104-5_27
[Maitre2026] (Submitted to TIP) Maitre, T., Bretin, E., Mahieu-Williame, L., Phan, R., Sdika, M., & Ducros, N. (2025). Dual-arm motion-compensated single-pixel imaging. HAL Id: hal-05068181
Methods
adjoint(m[, unvectorize])Apply adjoint of matrix \(H_{\rm{dyn}}\).
build_dynamic_forward(motion[, mode, ...])Builds the dynamic forward operator \(H_{\rm{dyn}}\).
forward(x)Simulates noisy dynamic measurements.
Simulates noisy dynamic measurements with the dynamic matrix
measure(x)Simulates noiseless measurements.
Simulates noiseless dynamic measurements with the dynamic matrix
set_matrix_to_inverse(matrix_name)unvectorize(input)Unflatten the measured dimensions.
vectorize(input)Flatten the measured dimensions.