Applies fourier transform and shifts the zero-frequency component to the center of the spectrum. Only the spatial dimensions get transformed. Args: x: Image to transform. spatial_dims: Number of spatial dimensions. as_contiguous: Whether
(x: NdarrayOrTensor, spatial_dims: int, as_contiguous: bool = False)
| 1880 | |
| 1881 | @staticmethod |
| 1882 | def shift_fourier(x: NdarrayOrTensor, spatial_dims: int, as_contiguous: bool = False) -> NdarrayOrTensor: |
| 1883 | """ |
| 1884 | Applies fourier transform and shifts the zero-frequency component to the |
| 1885 | center of the spectrum. Only the spatial dimensions get transformed. |
| 1886 | |
| 1887 | Args: |
| 1888 | x: Image to transform. |
| 1889 | spatial_dims: Number of spatial dimensions. |
| 1890 | as_contiguous: Whether to convert the cached NumPy array or PyTorch tensor to be contiguous. |
| 1891 | |
| 1892 | Returns |
| 1893 | k: K-space data. |
| 1894 | """ |
| 1895 | dims = tuple(range(-spatial_dims, 0)) |
| 1896 | k: NdarrayOrTensor |
| 1897 | if isinstance(x, torch.Tensor): |
| 1898 | k = torch.fft.fftshift(torch.fft.fftn(x, dim=dims), dim=dims) |
| 1899 | else: |
| 1900 | k = np.fft.fftshift(np.fft.fftn(x, axes=dims), axes=dims) |
| 1901 | return ascontiguousarray(k) if as_contiguous else k |
| 1902 | |
| 1903 | @staticmethod |
| 1904 | def inv_shift_fourier(k: NdarrayOrTensor, spatial_dims: int, as_contiguous: bool = False) -> NdarrayOrTensor: |