Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
fslpy
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor 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
Michiel Cottaar
fslpy
Commits
9d471c02
Commit
9d471c02
authored
7 years ago
by
Paul McCarthy
Browse files
Options
Downloads
Patches
Plain Diff
unit test for behaviour of init() with xform/header combinations
parent
d635bdae
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/test_image.py
+82
-0
82 additions, 0 deletions
tests/test_image.py
with
82 additions
and
0 deletions
tests/test_image.py
+
82
−
0
View file @
9d471c02
...
@@ -30,6 +30,7 @@ import fsl.utils.transform as transform
...
@@ -30,6 +30,7 @@ import fsl.utils.transform as transform
from
.
import
make_random_image
from
.
import
make_random_image
from
.
import
make_dummy_file
from
.
import
make_dummy_file
from
.
import
testdir
from
.
import
testdir
from
.
import
tempdir
def
make_image
(
filename
=
None
,
def
make_image
(
filename
=
None
,
...
@@ -1081,3 +1082,84 @@ def test_image_resample(seed):
...
@@ -1081,3 +1082,84 @@ def test_image_resample(seed):
resampled
=
img
.
resample
((
15
,
15
,
15
),
slc
)[
0
]
resampled
=
img
.
resample
((
15
,
15
,
15
),
slc
)[
0
]
assert
tuple
(
resampled
.
shape
)
==
(
15
,
15
,
15
)
assert
tuple
(
resampled
.
shape
)
==
(
15
,
15
,
15
)
def
test_Image_init_xform_nifti1
():
_test_Image_init_xform
(
1
)
def
test_Image_init_xform_nifti2
():
_test_Image_init_xform
(
2
)
def
_test_Image_init_xform
(
imgtype
):
with
tempdir
()
as
td
:
sform
=
transform
.
compose
(
np
.
random
.
random
(
3
),
np
.
random
.
random
(
3
),
np
.
random
.
random
(
3
))
qform
=
transform
.
compose
(
np
.
random
.
random
(
3
),
np
.
random
.
random
(
3
),
np
.
random
.
random
(
3
))
sform_code
=
3
qform_code
=
4
# Create a base nifti image
img
=
make_image
(
'
file.nii
'
)
img
.
set_sform
(
sform
,
code
=
sform_code
)
img
.
set_qform
(
qform
,
code
=
qform_code
)
nib
.
save
(
img
,
'
file.nii
'
)
img
=
nib
.
load
(
'
file.nii
'
)
# an image created off a
# header should have
# identical sform/qform
fimg
=
fslimage
.
Image
(
img
.
get_data
(),
header
=
img
.
header
)
fsform
,
fsform_code
=
fimg
.
header
.
get_sform
(
True
)
fqform
,
fqform_code
=
fimg
.
header
.
get_qform
(
True
)
xform
=
fimg
.
voxToWorldMat
assert
np
.
all
(
np
.
isclose
(
fsform
,
sform
))
assert
np
.
all
(
np
.
isclose
(
fqform
,
qform
))
assert
np
.
all
(
np
.
isclose
(
xform
,
sform
))
assert
fsform_code
==
sform_code
assert
fqform_code
==
qform_code
# an image created off
# an xform only should
# get its sform set
# set to that xform,
# qform to None, and
# and codes set to (s2, q0)
fimg
=
fslimage
.
Image
(
img
.
get_data
(),
xform
=
sform
)
fsform
,
fsform_code
=
fimg
.
header
.
get_sform
(
True
)
fqform
,
fqform_code
=
fimg
.
header
.
get_qform
(
True
)
xform
=
fimg
.
voxToWorldMat
assert
np
.
all
(
np
.
isclose
(
fsform
,
sform
))
assert
np
.
all
(
np
.
isclose
(
xform
,
sform
))
assert
fqform
is
None
assert
fsform_code
==
2
assert
fqform_code
==
0
# an image created with a
# header and an xform should
# have its s/q forms set
# to the xform. and its
# s/q form codes the same
# as what is in the header
rxform
=
transform
.
compose
(
np
.
random
.
random
(
3
),
np
.
random
.
random
(
3
),
np
.
random
.
random
(
3
))
fimg
=
fslimage
.
Image
(
img
.
get_data
(),
header
=
img
.
header
,
xform
=
rxform
)
fsform
,
fsform_code
=
fimg
.
header
.
get_sform
(
True
)
fqform
,
fqform_code
=
fimg
.
header
.
get_qform
(
True
)
xform
=
fimg
.
voxToWorldMat
assert
np
.
all
(
np
.
isclose
(
fsform
,
rxform
))
assert
np
.
all
(
np
.
isclose
(
fqform
,
rxform
))
assert
np
.
all
(
np
.
isclose
(
xform
,
rxform
))
assert
fsform_code
==
sform_code
assert
fqform_code
==
qform_code
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment