Commit bd2f311a authored by Paul McCarthy's avatar Paul McCarthy 🚵
Browse files

TEST: Test -ds scaledVoxel with L/R flipped images

parent c6de9ea6
......@@ -672,6 +672,40 @@ def fliporient(filename):
return outfile
def swapdim(filename, d0, d1, d2):
indices = { 'x' : 0, '-x' : 0,
'y' : 1, '-y' : 1,
'z' : 2, '-z' : 2}
base = fslimage.removeExt(filename)
outfile = '{}_swapdim_{}_{}_{}'.format(base, d0, d1, d2)
img = fslimage.Image(filename)
s0, s1, s2 = [-1 if d.startswith('-') else 1 for d in (d0, d1, d2)]
d0, d1, d2 = [indices[d] for d in (d0, d1, d2)]
if len(img.shape) == 3:
order = (d0, d1, d2)
else:
order = (d0, d1, d2) + tuple(range(3, len(img.shape)))
data = img.data
if s0 < 0: data = np.flip(data, d0)
if s1 < 0: data = np.flip(data, d1)
if s2 < 0: data = np.flip(data, d2)
data = data.transpose(order)
aff = np.zeros((4, 4))
aff[0, d0] = s0
aff[1, d1] = s1
aff[2, d2] = s2
aff[3, 3] = 1
aff = affine.concat(aff, img.voxToWorldMat)
img = fslimage.Image(data, xform=aff)
img.save(outfile)
return outfile
def roi(fname, roi):
......
......@@ -7,7 +7,7 @@
import pytest
from fsleyes.tests import run_cli_tests, resampled, roi, rotate
from fsleyes.tests import run_cli_tests, resampled, roi, rotate, swapdim
pytestmark = pytest.mark.clitest
......@@ -24,6 +24,16 @@ tests = """
-ds 3d_rotated_20_20_20 3d {{rotate('3d', 20, 20, 20)}} -cm red-yellow -a 50
-ds world 3d {{rotate('3d', 20, 20, 20)}} -cm red-yellow -a 50
-ds scaledVoxel 3d {{rotate('3d', 20, 20, 20)}} -cm red-yellow -a 50
-ds 3d 3d {{swapdim('3d', '-x', 'y', 'z')}} -cm red-yellow -a 50
-ds 3d_swapdim_-x_y_z 3d {{swapdim('3d', '-x', 'y', 'z')}} -cm red-yellow -a 50
-ds scaledVoxel 3d {{swapdim('3d', '-x', 'y', 'z')}} -cm red-yellow -a 50
-ds world 3d {{swapdim('3d', '-x', 'y', 'z')}} -cm red-yellow -a 50
-ds 3d 3d {{resampled(swapdim('3d', '-x', 'y', 'z'), 0.5)}} -cm red-yellow -a 50
-ds 3d_swapdim_-x_y_z_resampled_0.5 3d {{resampled(swapdim('3d', '-x', 'y', 'z'), 0.5)}} -cm red-yellow -a 50
-ds scaledVoxel 3d {{resampled(swapdim('3d', '-x', 'y', 'z'), 0.5)}} -cm red-yellow -a 50
-ds world 3d {{resampled(swapdim('3d', '-x', 'y', 'z'), 0.5)}} -cm red-yellow -a 50
"""
......@@ -31,6 +41,7 @@ def test_displayspace():
extras = {
'roi' : roi,
'resampled' : resampled,
'rotate' : rotate
'rotate' : rotate,
'swapdim' : swapdim
}
run_cli_tests('test_displayspace', tests, extras=extras)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment