Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
pyfeeds-tests
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
FSL
pyfeeds-tests
Merge requests
!43
Test that applywarp --usesqform adheres to FSL sform/qform usage conventions.
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Test that applywarp --usesqform adheres to FSL sform/qform usage conventions.
mnt/applywarp-usesqform-unit-test
into
master
Overview
0
Commits
1
Pipelines
3
Changes
1
Merged
Paul McCarthy
requested to merge
mnt/applywarp-usesqform-unit-test
into
master
2 years ago
Overview
0
Commits
1
Pipelines
3
Changes
1
Expand
This test will fail until
fugue!6 (merged)
is merged
0
0
Merge request reports
Viewing commit
3ef32258
Show latest version
1 file
+
80
−
0
Side-by-side
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
3ef32258
Test that applywarp --usesqform adheres to FSL sform/qform usage
· 3ef32258
Paul McCarthy
authored
2 years ago
conventions.
unit_tests/fugue/applywarp/feedsRun
0 → 100755
+
80
−
0
Options
#!/usr/bin/env fslpython
import shlex
import subprocess as sp
import numpy as np
import nibabel as nib
from fsl.data.image import Image
import fsl.transform.affine as affine
def applywarp(src, ref):
cmd = f'applywarp --in={src} --ref={ref} --usesqform --out=out'
sp.run(shlex.split(cmd), check=True)
return Image('out')
def make_image(fname, data, sform, sform_code, qform, qform_code):
hdr = nib.Nifti1Header()
hdr.set_sform(sform, sform_code)
hdr.set_qform(qform, qform_code)
img = Image(data, header=hdr)
img.save(fname)
return img
# fsl/fugue!6
#
# Make sure that applywarp --usesqform
# will correctly use the sform or qform
#
# FSL affine precedence rules are as follows:
#
# 1. If sform_code != 0, use sform; else
# 2. If qform_code != 0, use qform; else
# 3. Use a scaling matrix with pixdims along the
# diagonal
def test_applywarp_uses_sqform_correctly():
srcdata = np.zeros((20, 20, 20))
refdata = np.zeros((20, 20, 20))
# Data from the two images
# aligned via their affines -
# src should be resampled so
# as to be identical to ref
srcdata[ 6: 9, 6: 9, 6: 9] = 1
refdata[16:19, 16:19, 16:19] = 1
eye = np.eye(4)
srcaff = affine.scaleOffsetXform(1, [ 5, 5, 5])
refaff = affine.scaleOffsetXform(1, [-5, -5, -5])
# aligned via sform
src = make_image('src', srcdata, srcaff, 2, eye, 1)
ref = make_image('ref', refdata, refaff, 2, eye, 1)
result = applywarp('src', 'ref')
assert np.all(np.isclose(result.data, ref.data))
# aligned via sform again
src = make_image('src', srcdata, srcaff, 2, eye, 0)
ref = make_image('ref', refdata, refaff, 2, eye, 0)
result = applywarp('src', 'ref')
assert np.all(np.isclose(result.data, ref.data))
# aligned via qform
src = make_image('src', srcdata, eye, 0, srcaff, 2)
ref = make_image('ref', refdata, eye, 0, refaff, 2)
result = applywarp('src', 'ref')
assert np.all(np.isclose(result.data, ref.data))
# not aligned
src = make_image('src', srcdata, eye, 0, srcaff, 0)
ref = make_image('ref', refdata, eye, 0, refaff, 0)
result = applywarp('src', 'ref')
assert not np.all(np.isclose(result.data, ref.data))
assert np.all(np.isclose(result.data, src.data))
if __name__ == '__main__':
test_applywarp_uses_sqform_correctly()
Loading