spyrit.core.meas.DynamicLinearSplit

class spyrit.core.meas.DynamicLinearSplit(H: tensor, Ord: tensor = None, meas_shape: tuple = None, img_shape: tuple = None)[source]

Bases: DynamicLinear

Simulates the measurement of a moving object using a splitted operator \(y = \begin{bmatrix}{H_{+}}\\{H_{-}}\end{bmatrix} \cdot x(t)\).

Computes linear measurements \(y\) from incoming images: \(y = Px\), where \(P\) is a linear operator (matrix) and \(x\) is a batch of vectorized images representing a motion picture.

The matrix \(P\) contains only positive values and is obtained by splitting a measurement matrix \(H\) such that \(P\) has a shape of \((2M, N)\) and P[0::2, :] = H_{+} and P[1::2, :] = H_{-}, where \(H_{+} = \max(0,H)\) and \(H_{-} = \max(0,-H)\).

The class is constructed from the \(M\) by \(N\) matrix \(H\), where \(N\) represents the number of pixels in the image and \(M\) the number of measurements. Therefore, the shape of \(P\) is \((2M, N)\).

Args:

H (torch.tensor): measurement matrix (linear operator) with shape \((M, N)\) where \(M\) is the number of measurements and \(N\) the number of pixels in the image. Only real values are supported.

Ord (torch.tensor, optional): Order matrix used to reorder the rows of the measurement matrix \(H\). The first new row of \(H\) will correspond to the highest value in \(Ord\). Must contain \(M\) values. If some values repeat, the order is kept. Defaults to None.

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.

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.

Attributes:

H_static (torch.nn.Parameter): The learnable measurement matrix of shape \((M,N)\) initialized as \(H\).

P (torch.nn.Parameter): The splitted measurement matrix of shape \((2M, N)\) such that P[0::2, :] = H_{+} and P[1::2, :] = H_{-}.

M (int): Number of measurements performed by the linear operator.

N (int): Number of pixels in the image.

h (int): Measurement pattern height.

w (int): Measurement pattern width.

meas_shape (tuple): Shape of the measurement patterns (height, width). Is equal to (self.h, self.w).

img_h (int): Image height.

img_w (int): Image width.

img_shape (tuple): Shape of the image (height, width). Is equal to (self.img_h, self.img_w).

H_dyn (torch.tensor): Dynamic measurement matrix \(H\). Must be set using the method build_H_dyn() before being accessed.

H (torch.tensor): Alias for H_dyn.

H_dyn_pinv (torch.tensor): Dynamic pseudo-inverse measurement matrix \(H_{dyn}^\dagger\). Must be set using the method build_H_dyn_pinv() before being accessed.

H_pinv (torch.tensor): Alias for H_dyn_pinv.

Warning

For each call, there must be exactly as many images in \(x\) as there are measurements in the linear operator \(P\).

Example:
>>> H = torch.rand([400,1600])
>>> meas_op = DynamicLinearSplit(H)
>>> print(meas_op)
DynamicLinearSplit(
  (M): 400
  (N): 1600
  (H.shape): torch.Size([400, 1600])
  (meas_shape): (40, 40)
  (H_dyn): False
  (img_shape): (40, 40)
  (H_pinv): False
  (P.shape): torch.Size([800, 1600])
)

Reference: .. _MICCAI24:

[MaBP24] (MICCAI 2024 paper #883) Thomas Maitre, Elie Bretin, Romain Phan, Nicolas Ducros, Michaël Sdika. Dynamic Single-Pixel Imaging on an Extended Field of View without Warping the Patterns. 2024. hal-04533981

Methods

build_H_dyn(motion[, mode])

Build the dynamic measurement matrix H_dyn.

build_H_dyn_pinv([reg, eta])

Computes the pseudo-inverse of the dynamic measurement matrix H_dyn and stores it in the attribute H_dyn_pinv.

forward(x)

Simulates the measurement of a motion picture \(y = P \cdot x(t)\).

forward_H(x)

Simulates the measurement of a motion picture \(y = H \cdot x(t)\).

forward_H_dyn(x)

Simulates the acquisition of measurements using the dynamic measurement matrix H_dyn.

pinv(x[, reg, eta, diff])

Computes the pseudo inverse solution \(y = H^\dagger x\).

reindex(x[, axis, inverse_permutation])

Sorts a tensor along a specified axis using the indices tensor.

unvectorize(input)

Reshape a vectorized tensor to the measurement shape (heigth, width).

vectorize(input)

Vectorize an image-shaped tensor.