Skip to content
Snippets Groups Projects
Commit 651b83b2 authored by Paul McCarthy's avatar Paul McCarthy :mountain_bicyclist:
Browse files

New tests for flirt -applyxfm

parent 4004ee9b
No related branches found
No related tags found
1 merge request!72Basic tests for `flirt -applyxfm`
Pipeline #27032 skipped
File added
File added
File added
File added
File added
#!/usr/bin/env fslpython
#
# Test basic flirt -applyxfm behaviour
#
import os.path as op
import os
import sys
import fsl.data.image as fslimage
import fsl.utils.run as run
import numpy as np
thisdir = op.dirname(op.abspath(__file__))
def compare_images(a, b):
print(f'Comparing images {a} and {b}')
a = fslimage.Image(a)
b = fslimage.Image(b)
adata = a.data
bdata = b.data
assert a.sameSpace(b)
assert np.all(np.isclose(adata, bdata))
def test_applyxfm():
fsldir = os.environ['FSLDIR']
std2mm = op.join(fsldir, 'data', 'standard', 'MNI152_T1_2mm.nii.gz')
std1mm = op.join(fsldir, 'data', 'standard', 'MNI152_T1_1mm.nii.gz')
std2mm_roi = 'std2mm_roi.nii.gz'
# use a ROI to reduce storage and test extrapolation behaviour
run.runfsl(f'fslroi {std2mm} {std2mm_roi} 40 10 40 10 40 10')
tests = [
'-applyxfm -usesqform -interp nearestneighbour',
'-applyxfm -usesqform -interp trilinear',
'-applyxfm -usesqform -interp sinc',
'-applyxfm -usesqform -interp spline',
'-applyxfm -usesqform -interp spline -setbackground 0',
]
for test in tests:
outfname = '_'.join(test.replace('-', '').split())
outfname = f'{outfname}.nii.gz'
cmd = f'flirt -in {std2mm_roi} -ref {std1mm} -out {outfname} {test}'
run.runfsl(cmd)
expfname = op.join(thisdir, 'benchmarks', outfname)
compare_images(outfname, expfname)
if __name__ == '__main__':
if len(sys.argv) > 1:
os.chdir(sys.argv[1])
test_applyxfm()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment