MCPcopy Create free account
hub / github.com/Project-MONAI/MONAI / shift_fourier

Method shift_fourier

monai/transforms/utils.py:1882–1901  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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:

Callers 4

test_forwardMethod · 0.95
__call__Method · 0.80
__call__Method · 0.80
_set_default_rangeMethod · 0.80

Calls 1

ascontiguousarrayFunction · 0.90

Tested by 1

test_forwardMethod · 0.76