spyrit.core.meas.DynamicHadamSplit
- class spyrit.core.meas.DynamicHadamSplit(M: int, h: int, Ord: tensor = None, img_shape: tuple = None)[source]
Bases:
DynamicLinearSplitSimulates the measurement of a moving object using a splitted operator \(y = \begin{bmatrix}{H_{+}}\\{H_{-}}\end{bmatrix} \cdot x(t)\) with \(H\) a Hadamard matrix.
Computes linear measurements from incoming images: \(y = Px\), where \(P\) is a linear operator (matrix) with positive entries 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 Hadamard-based 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)\).
\(H\) is obtained by selecting a re-ordered subsample of \(M\) rows of a “full” Hadamard matrix \(F\) with shape \((N^2, N^2)\). \(N\) must be a power of 2.
- Args:
M(int): Number of measurements. If \(M < h^2\), the measurement matrix \(H\) is cropped to \(M\) rows.h(int): Measurement pattern height, must be a power of 2. The image is assumed to be square, so the number of pixels in the image is \(N = h^2\).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.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 methodbuild_H_dyn()before being accessed.H(torch.tensor): Alias forH_dyn.H_dyn_pinv(torch.tensor): Dynamic pseudo-inverse measurement matrix \(H_{dyn}^\dagger\). Must be set using the methodbuild_H_dyn_pinv()before being accessed.H_pinv(torch.tensor): Alias forH_dyn_pinv.
Note
The computation of a Hadamard transform \(Fx\) benefits a fast algorithm, as well as the computation of inverse Hadamard transforms.
Note
\(H = H_{+} - H_{-}\)
- Example:
>>> Ord = torch.rand([32,32]) >>> meas_op = HadamSplitDynamic(400, 32, Ord) >>> print(meas_op) DynamicHadamSplit( (M): 400 (N): 1024 (H.shape): torch.Size([400, 1024]) (meas_shape): (32, 32) (H_dyn): False (img_shape): (32, 32) (H_pinv): False (P.shape): torch.Size([800, 1024]) )
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)\).
pinv(x[, reg, eta])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.