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

Class Fourier

monai/transforms/utils.py:1876–1923  ·  view source on GitHub ↗

Helper class storing Fourier mappings

Source from the content-addressed store, hash-verified

1874
1875
1876class Fourier:
1877 """
1878 Helper class storing Fourier mappings
1879 """
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:
1905 """
1906 Applies inverse shift and fourier transform. Only the spatial
1907 dimensions are transformed.
1908
1909 Args:
1910 k: K-space data.
1911 spatial_dims: Number of spatial dimensions.
1912 as_contiguous: Whether to convert the cached NumPy array or PyTorch tensor to be contiguous.
1913
1914 Returns:
1915 x: Tensor in image space.
1916 """
1917 dims = tuple(range(-spatial_dims, 0))
1918 out: NdarrayOrTensor
1919 if isinstance(k, torch.Tensor):
1920 out = torch.fft.ifftn(torch.fft.ifftshift(k, dim=dims), dim=dims, norm="backward").real
1921 else:
1922 out = np.fft.ifftn(np.fft.ifftshift(k, axes=dims), axes=dims).real
1923 return ascontiguousarray(out) if as_contiguous else out
1924
1925
1926def get_number_image_type_conversions(transform: Compose, test_data: Any, key: Hashable | None = None) -> int:

Callers 2

test_forwardMethod · 0.90
test_backwardMethod · 0.90

Calls

no outgoing calls

Tested by 2

test_forwardMethod · 0.72
test_backwardMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…