Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions src/mrpro/operators/functionals/SSIM.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,8 @@ def forward(self, x: torch.Tensor) -> tuple[torch.Tensor]:
See this PyTorch `discussion <https://discuss.pytorch.org/t/is-model-forward-x-the-same-as-model-call-x/33460/3>`_.
"""
ssim = ssim3d(
self.target.real,
x.real,
self.target,
x,
weight=self.weight,
k1=self.k1,
k2=self.k2,
Expand Down
13 changes: 13 additions & 0 deletions tests/operators/functionals/test_ssim.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,16 @@ def test_ssim_reduction() -> None:
assert ssim_volume.shape == (2, 3)
assert ssim_full.shape == ()
assert ssim_none.shape == (2, 3, 4, 4, 4)


def test_ssim_complex() -> None:
"""Test the SSIM functional for complex-valued tensors."""
rng = RandomGenerator(0)
target_real = rng.float32_tensor((1, 10, 10), low=0.0, high=1.0)
target_imag = rng.float32_tensor((1, 10, 10), low=0.0, high=1.0)
target = target_real + 1j * target_imag
test = rng.complex64_tensor((1, 10, 10), low=0.0, high=1.0)

torch.testing.assert_close(
SSIM(target)(test)[0], 0.5 * (SSIM(target.real)(test.real)[0] + (SSIM(target.imag)(test.imag)[0]))
)
Loading