spyrit.core.torch.walsh2_torch
- spyrit.core.torch.walsh2_torch(img, H=None)[source]
Return 2D Walsh-ordered Hadamard transform of an image
This applies the 1D transform \(H \in \mathbb{R}^{n \times n}\) to the rows and to the columns of batches of images \(X\in \mathbb{R}^{n \times n}\)
\[Y = H X H^T.\]- Args:
img(torch.tensor): Batch of images \(X\) with shape \((*,n,n)\).H(torch.tensor, optional): 1D Walsh-ordered Hadamard matrix with shape \((n,n)\).- Returns:
torch.tensor: Transformed image \(Y\) with shape \((*, n, n)\) where \(*\) is the same number as forimg.- See Also:
fwht_2d()implements the same transform with a different algorithm.- Example:
Example 1: Basic example
>>> img = torch.randn(256, 1, 64, 64) >>> had = walsh2_torch(img)
Example 2: Same on CPU
>>> img = torch.randn(256, 1, 64, 64) >>> img = img.to(device='cpu') >>> had = walsh2_torch(img) >>> print(had.device) cpu
Example 3: On GPU using
torch.float64>>> img = torch.randn(256, 1, 64, 64) >>> img = img.to(device='cpu', dtype=torch.float64) >>> had = walsh2_torch(img) >>> print(had.device,'+',had.dtype) cpu + torch.float64