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
d4830e7f
Commit
d4830e7f
authored
5 years ago
by
Paul McCarthy
Browse files
Options
Downloads
Patches
Plain Diff
TEST: More tests for resample_image script
parent
84bd4950
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/test_scripts/test_resample_image.py
+67
-5
67 additions, 5 deletions
tests/test_scripts/test_resample_image.py
with
67 additions
and
5 deletions
tests/test_scripts/test_resample_image.py
+
67
−
5
View file @
d4830e7f
...
@@ -15,10 +15,11 @@ from fsl.data.image import Image
...
@@ -15,10 +15,11 @@ from fsl.data.image import Image
from
..
import
make_random_image
from
..
import
make_random_image
def
test_resample_image_shape
():
def
test_resample_image_shape
():
with
tempdir
():
with
tempdir
():
img
=
Image
(
make_random_image
(
'
image.nii.gz
'
,
dims
=
(
10
,
10
,
10
)))
img
=
Image
(
make_random_image
(
'
image.nii.gz
'
,
dims
=
(
10
,
10
,
10
)))
resample_image
.
main
(
'
image resampled -s 20
20
20
'
.
split
())
resample_image
.
main
(
'
image resampled -s 20
,
20
,
20
'
.
split
())
res
=
Image
(
'
resampled
'
)
res
=
Image
(
'
resampled
'
)
expv2w
=
transform
.
concat
(
expv2w
=
transform
.
concat
(
...
@@ -32,18 +33,36 @@ def test_resample_image_shape():
...
@@ -32,18 +33,36 @@ def test_resample_image_shape():
np
.
array
(
transform
.
axisBounds
(
res
.
shape
,
res
.
voxToWorldMat
))
-
0.25
,
np
.
array
(
transform
.
axisBounds
(
res
.
shape
,
res
.
voxToWorldMat
))
-
0.25
,
transform
.
axisBounds
(
img
.
shape
,
img
.
voxToWorldMat
)))
transform
.
axisBounds
(
img
.
shape
,
img
.
voxToWorldMat
)))
resample_image
.
main
(
'
image resampled -s 20
20
20 -o corner
'
.
split
())
resample_image
.
main
(
'
image resampled -s 20
,
20
,
20 -o corner
'
.
split
())
res
=
Image
(
'
resampled
'
)
res
=
Image
(
'
resampled
'
)
assert
np
.
all
(
np
.
isclose
(
assert
np
.
all
(
np
.
isclose
(
transform
.
axisBounds
(
res
.
shape
,
res
.
voxToWorldMat
),
transform
.
axisBounds
(
res
.
shape
,
res
.
voxToWorldMat
),
transform
.
axisBounds
(
img
.
shape
,
img
.
voxToWorldMat
)))
transform
.
axisBounds
(
img
.
shape
,
img
.
voxToWorldMat
)))
def
test_resample_image_shape_4D
():
with
tempdir
():
# Can specify three dims
img
=
Image
(
make_random_image
(
'
image.nii.gz
'
,
dims
=
(
10
,
10
,
10
,
10
)))
resample_image
.
main
(
'
image resampled -s 20,20,20
'
.
split
())
res
=
Image
(
'
resampled
'
)
assert
np
.
all
(
np
.
isclose
(
res
.
shape
,
(
20
,
20
,
20
,
10
)))
assert
np
.
all
(
np
.
isclose
(
res
.
pixdim
,
(
0.5
,
0.5
,
0.5
,
1
)))
# Or resample along the higher dims
resample_image
.
main
(
'
image resampled -s 20,20,20,20
'
.
split
())
res
=
Image
(
'
resampled
'
)
assert
np
.
all
(
np
.
isclose
(
res
.
shape
,
(
20
,
20
,
20
,
20
)))
assert
np
.
all
(
np
.
isclose
(
res
.
pixdim
,
(
0.5
,
0.5
,
0.5
,
0.5
)))
def
test_resample_image_dim
():
def
test_resample_image_dim
():
with
tempdir
():
with
tempdir
():
img
=
Image
(
make_random_image
(
'
image.nii.gz
'
,
dims
=
(
10
,
10
,
10
)))
img
=
Image
(
make_random_image
(
'
image.nii.gz
'
,
dims
=
(
10
,
10
,
10
)))
resample_image
.
main
(
'
image resampled -d 0.5
0.5
0.5
'
.
split
())
resample_image
.
main
(
'
image resampled -d 0.5
,
0.5
,
0.5
'
.
split
())
res
=
Image
(
'
resampled
'
)
res
=
Image
(
'
resampled
'
)
expv2w
=
transform
.
concat
(
expv2w
=
transform
.
concat
(
...
@@ -70,12 +89,55 @@ def test_resample_image_ref():
...
@@ -70,12 +89,55 @@ def test_resample_image_ref():
assert
np
.
all
(
np
.
isclose
(
res
.
pixdim
,
(
0.5
,
0.5
,
0.5
)))
assert
np
.
all
(
np
.
isclose
(
res
.
pixdim
,
(
0.5
,
0.5
,
0.5
)))
assert
np
.
all
(
np
.
isclose
(
res
.
voxToWorldMat
,
expv2w
))
assert
np
.
all
(
np
.
isclose
(
res
.
voxToWorldMat
,
expv2w
))
# 3D / 4D
img
=
Image
(
make_random_image
(
'
image.nii.gz
'
,
dims
=
(
10
,
10
,
10
)))
ref
=
Image
(
make_random_image
(
'
ref.nii.gz
'
,
dims
=
(
20
,
20
,
20
,
20
),
pixdims
=
(
0.5
,
0.5
,
0.5
,
1
)))
resample_image
.
main
(
'
image resampled -r ref
'
.
split
())
res
=
Image
(
'
resampled
'
)
assert
np
.
all
(
np
.
isclose
(
res
.
shape
,
(
20
,
20
,
20
)))
assert
np
.
all
(
np
.
isclose
(
res
.
pixdim
,
(
0.5
,
0.5
,
0.5
)))
# 4D / 3D
img
=
Image
(
make_random_image
(
'
image.nii.gz
'
,
dims
=
(
10
,
10
,
10
,
10
)))
ref
=
Image
(
make_random_image
(
'
ref.nii.gz
'
,
dims
=
(
20
,
20
,
20
),
pixdims
=
(
0.5
,
0.5
,
0.5
)))
resample_image
.
main
(
'
image resampled -r ref
'
.
split
())
res
=
Image
(
'
resampled
'
)
assert
np
.
all
(
np
.
isclose
(
res
.
shape
,
(
20
,
20
,
20
,
10
)))
assert
np
.
all
(
np
.
isclose
(
res
.
pixdim
,
(
0.5
,
0.5
,
0.5
,
1
)))
# 4D / 4D - no resampling along fourth dim
img
=
Image
(
make_random_image
(
'
image.nii.gz
'
,
dims
=
(
10
,
10
,
10
,
10
)))
ref
=
Image
(
make_random_image
(
'
ref.nii.gz
'
,
dims
=
(
20
,
20
,
20
,
20
),
pixdims
=
(
0.5
,
0.5
,
0.5
,
1
)))
resample_image
.
main
(
'
image resampled -r ref
'
.
split
())
res
=
Image
(
'
resampled
'
)
assert
np
.
all
(
np
.
isclose
(
res
.
shape
,
(
20
,
20
,
20
,
10
)))
assert
np
.
all
(
np
.
isclose
(
res
.
pixdim
,
(
0.5
,
0.5
,
0.5
,
1
)))
def
test_resample_image_bad_options
():
def
test_resample_image_bad_options
():
with
tempdir
():
with
tempdir
():
img
=
Image
(
make_random_image
(
'
image.nii.gz
'
,
dims
=
(
10
,
10
,
10
)))
img
=
Image
(
make_random_image
(
'
image.nii.gz
'
,
dims
=
(
10
,
10
,
10
)))
# No args - should print help and exit(0)
with
pytest
.
raises
(
SystemExit
)
as
e
:
resample_image
.
main
([])
assert
e
.
value
.
code
==
0
with
pytest
.
raises
(
SystemExit
)
as
e
:
resample_image
.
main
(
'
image resampled -d 0.5,0.5,0.5
'
'
-s 20,20,20
'
.
split
())
assert
e
.
value
.
code
!=
0
with
pytest
.
raises
(
SystemExit
)
as
e
:
resample_image
.
main
(
'
image resampled -s 20,20
'
.
split
())
assert
e
.
value
.
code
!=
0
with
pytest
.
raises
(
SystemExit
)
as
e
:
with
pytest
.
raises
(
SystemExit
)
as
e
:
resample_image
.
main
(
'
image resampled -d 0.5 0.5 0.5
'
resample_image
.
main
(
'
image resampled -s 20,20,20,20
'
.
split
())
'
-s 20 20 20
'
.
split
())
assert
e
.
value
.
code
!=
0
assert
e
.
value
.
code
!=
0
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