Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions monai/networks/blocks/fft_utils_t.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,20 +187,19 @@ def fftn_centered_t(im: Tensor, spatial_dims: int, is_complex: bool = True) -> T
output2 = fftn_centered(im, spatial_dims=2, is_complex=True)
"""
# define spatial dims to perform ifftshift, fftshift, and fft
shift = list(range(-spatial_dims, 0))
dims = list(range(-spatial_dims, 0))
if is_complex:
if im.shape[-1] != 2:
raise ValueError(f"img.shape[-1] is not 2 ({im.shape[-1]}).")
shift = list(range(-spatial_dims - 1, -1))
dims = list(range(-spatial_dims, 0))

x = ifftshift(im, shift)
x = ifftshift(im, [d - 1 for d in dims])
else:
x = ifftshift(im, dims)

if is_complex:
x = torch.view_as_real(torch.fft.fftn(torch.view_as_complex(x), dim=dims, norm="ortho"))
else:
x = torch.view_as_real(torch.fft.fftn(x, dim=dims, norm="ortho"))

out: Tensor = fftshift(x, shift)
out: Tensor = fftshift(x, [d - 1 for d in dims])

return out
2 changes: 1 addition & 1 deletion tests/data/test_fft_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#
im = [[[1.0, 1.0, 1.0], [1.0, 1.0, 1.0], [1.0, 1.0, 1.0]]]
res = [
[[[0.0, 0.0], [0.0, 3.0], [0.0, 0.0]], [[0.0, 0.0], [0.0, 0.0], [0.0, 0.0]], [[0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]]
[[[0.0, 0.0], [0.0, 0.0], [0.0, 0.0]], [[0.0, 0.0], [3.0, 0.0], [0.0, 0.0]], [[0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]]
]
TESTS = []
for p in TEST_NDARRAYS:
Expand Down
Loading