spyrit.core.torch.walsh2_torch
- spyrit.core.torch.walsh2_torch(img, H=None)[source]
Returns a 2D Walsh-ordered Hadamard transform of an image.
- Args:
img (torch.tensor): Image to transform. Must have a shape of \((*, h, w)\) where \(h\) and \(w\) are the image height and width. The image must be square, i.e. \(h = w\). The image height and width must be a power of two.
H (torch.tensor, optional): 1D Walsh-ordered Hadamard transformation matrix. Specify this if you have already calculated the transformation matrix, or leave this field to None to have the transformation matrix calculated. Defaults to None.
- Returns:
torch.tensor: Hadamard-transformed image. Has same shape as input image.
- Example:
>>> img = torch.rand(1, 3, 64, 64) # (batch, channels, height, width) >>> img_transformed = walsh2_torch(img) >>> img_transformed.shape torch.Size([1, 3, 64, 64])