From 31fcd1a1ca795dd90d92d6e3aefa53a2c7d7cb33 Mon Sep 17 00:00:00 2001 From: Yunfeng Wang Date: Sun, 6 Sep 2026 13:39:23 +0800 Subject: [PATCH] fix: support non-square volumes in reslicing --- rtspm/_spm_reslice_rt.py | 2 +- tests/test_rtspm/test_spm.py | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/rtspm/_spm_reslice_rt.py b/rtspm/_spm_reslice_rt.py index 9b5406e..6415ba2 100644 --- a/rtspm/_spm_reslice_rt.py +++ b/rtspm/_spm_reslice_rt.py @@ -100,7 +100,7 @@ def spm_reslice_rt(r, flags): temp_x1 = np.transpose(np.array(range(1, r0_dim[0] + 1), ndmin=2)) x1 = np.tile(temp_x1, (1, r0_dim[1])) temp_x2 = np.transpose(np.array(range(1, r0_dim[1] + 1), ndmin=2)) - x2 = np.transpose(np.tile(temp_x2, (1, r0_dim[1]))) + x2 = np.transpose(np.tile(temp_x2, (1, r0_dim[0]))) if int(flags['mean']): count = np.zeros(r0_dim) diff --git a/tests/test_rtspm/test_spm.py b/tests/test_rtspm/test_spm.py index d47f65f..477ffae 100644 --- a/tests/test_rtspm/test_spm.py +++ b/tests/test_rtspm/test_spm.py @@ -1,9 +1,36 @@ import numpy as np +import importlib from rtspm import spm_realign_rt from rtspm import spm_reslice_rt +def test_spm_reslice_supports_non_square_in_plane_dimensions(monkeypatch): + module = importlib.import_module("rtspm._spm_reslice_rt") + monkeypatch.setattr( + module.spm, + "bsplins", + lambda _coefficients, y1, _y2, _y3, _degree: np.ones(y1.shape), + ) + dim = np.array([3, 5, 2]) + identity = np.eye(4) + r = [ + {"mat": identity, "dim": dim, "C": np.zeros(dim)}, + {"mat": identity, "dim": dim, "C": np.zeros(dim)}, + ] + flags = { + "interp": 1, + "wrap": np.zeros(3), + "mask": 1, + "mean": 0, + "which": 2, + } + + result = spm_reslice_rt(r, flags) + + assert result.shape == tuple(dim) + + def img_2d_to_3d(img2d, xdim_img_number, ydim_img_number, dim3d): sl = 0 vol3d = np.zeros(dim3d)