Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
fslpy
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Analyze
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
Evan Edmond
fslpy
Commits
7fee93d6
Commit
7fee93d6
authored
5 years ago
by
Paul McCarthy
Browse files
Options
Downloads
Patches
Plain Diff
TEST: Tests for new resample/nonlinear things. Empty apply_x5 test module
parent
15ddfed9
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
tests/test_image_resample.py
+25
-0
25 additions, 0 deletions
tests/test_image_resample.py
tests/test_scripts/test_fsl_apply_x5.py
+3
-0
3 additions, 0 deletions
tests/test_scripts/test_fsl_apply_x5.py
tests/test_transform/test_nonlinear.py
+84
-4
84 additions, 4 deletions
tests/test_transform/test_nonlinear.py
with
112 additions
and
4 deletions
tests/test_image_resample.py
+
25
−
0
View file @
7fee93d6
...
...
@@ -263,3 +263,28 @@ def test_resampleToReference3():
exp
=
np
.
array
([
refdata
[...,
0
]]
*
15
).
transpose
((
1
,
2
,
3
,
0
))
resampled
,
xform
=
resample
.
resampleToReference
(
img
,
ref
,
order
=
0
,
mode
=
'
nearest
'
)
assert
np
.
all
(
resampled
==
exp
)
def
test_resampleToReference4
():
# the image and ref are out of
# alignment, but this affine
# will bring them into alignment
img2ref
=
transform
.
scaleOffsetXform
([
2
,
2
,
2
],
[
10
,
10
,
10
])
imgdata
=
np
.
random
.
randint
(
0
,
65536
,
(
5
,
5
,
5
))
refdata
=
np
.
zeros
((
5
,
5
,
5
))
img
=
fslimage
.
Image
(
imgdata
)
ref
=
fslimage
.
Image
(
refdata
,
xform
=
img2ref
)
# Without the affine, the image
# will be out of the FOV of the
# reference
resampled
,
xform
=
resample
.
resampleToReference
(
img
,
ref
)
assert
np
.
all
(
resampled
==
0
)
# But applying the affine will
# cause them to overlap
# perfectly in world coordinates
resampled
,
xform
=
resample
.
resampleToReference
(
img
,
ref
,
matrix
=
img2ref
)
assert
np
.
all
(
resampled
==
imgdata
)
This diff is collapsed.
Click to expand it.
tests/test_scripts/test_fsl_apply_x5.py
0 → 100644
+
3
−
0
View file @
7fee93d6
#!/usr/bin/env python
# TODO
This diff is collapsed.
Click to expand it.
tests/test_transform/test_nonlinear.py
+
84
−
4
View file @
7fee93d6
...
...
@@ -5,10 +5,11 @@ import os.path as op
import
numpy
as
np
import
fsl.data.image
as
fslimage
import
fsl.transform.affine
as
affine
import
fsl.transform.nonlinear
as
nonlinear
import
fsl.transform.fnirt
as
fnirt
import
fsl.data.image
as
fslimage
import
fsl.utils.image.resample
as
resample
import
fsl.transform.affine
as
affine
import
fsl.transform.nonlinear
as
nonlinear
import
fsl.transform.fnirt
as
fnirt
datadir
=
op
.
join
(
op
.
dirname
(
__file__
),
'
testdata
'
)
...
...
@@ -40,6 +41,26 @@ def _random_field():
return
nonlinear
.
DeformationField
(
field
,
src
=
src
,
xform
=
aff
)
def
_affine_field
(
src
,
ref
,
xform
,
srcSpace
,
refSpace
):
rx
,
ry
,
rz
=
np
.
meshgrid
(
np
.
arange
(
ref
.
shape
[
0
]),
np
.
arange
(
ref
.
shape
[
1
]),
np
.
arange
(
ref
.
shape
[
2
]),
indexing
=
'
ij
'
)
rvoxels
=
np
.
vstack
((
rx
.
flatten
(),
ry
.
flatten
(),
rz
.
flatten
())).
T
rcoords
=
affine
.
transform
(
rvoxels
,
ref
.
getAffine
(
'
voxel
'
,
refSpace
))
scoords
=
affine
.
transform
(
rcoords
,
xform
)
field
=
np
.
zeros
(
list
(
ref
.
shape
[:
3
])
+
[
3
])
field
[:]
=
(
scoords
-
rcoords
).
reshape
(
*
it
.
chain
(
ref
.
shape
,
[
3
]))
field
=
nonlinear
.
DeformationField
(
field
,
src
,
ref
,
srcSpace
=
srcSpace
,
refSpace
=
refSpace
,
header
=
ref
.
header
,
defType
=
'
relative
'
)
return
field
def
_random_affine_field
():
src
=
_random_image
()
...
...
@@ -310,3 +331,62 @@ def test_coefficientFieldToDeformationField():
assert
np
.
all
(
np
.
isclose
(
acnv
.
data
,
adf
.
data
,
**
tol
))
assert
np
.
all
(
np
.
isclose
(
rcnvnp
.
data
,
rdfnp
.
data
,
**
tol
))
assert
np
.
all
(
np
.
isclose
(
acnvnp
.
data
,
adfnp
.
data
,
**
tol
))
def
test_applyDeformation
():
src2ref
=
affine
.
compose
(
np
.
random
.
randint
(
2
,
5
,
3
),
np
.
random
.
randint
(
1
,
10
,
3
),
np
.
random
.
random
(
3
))
ref2src
=
affine
.
invert
(
src2ref
)
srcdata
=
np
.
random
.
randint
(
1
,
65536
,
(
10
,
10
,
10
))
refdata
=
np
.
random
.
randint
(
1
,
65536
,
(
10
,
10
,
10
))
src
=
fslimage
.
Image
(
srcdata
)
ref
=
fslimage
.
Image
(
refdata
,
xform
=
src2ref
)
field
=
_affine_field
(
src
,
ref
,
ref2src
,
'
world
'
,
'
world
'
)
expect
,
xf
=
resample
.
resampleToReference
(
src
,
ref
,
matrix
=
src2ref
,
order
=
1
,
mode
=
'
nearest
'
)
result
=
nonlinear
.
applyDeformation
(
src
,
field
,
order
=
1
,
mode
=
'
nearest
'
)
assert
np
.
all
(
np
.
isclose
(
expect
,
result
))
def
test_applyDeformation_altref
():
src2ref
=
affine
.
compose
(
np
.
random
.
randint
(
2
,
5
,
3
),
np
.
random
.
randint
(
1
,
10
,
3
),
np
.
random
.
random
(
3
))
ref2src
=
affine
.
invert
(
src2ref
)
srcdata
=
np
.
random
.
randint
(
1
,
65536
,
(
10
,
10
,
10
))
refdata
=
np
.
random
.
randint
(
1
,
65536
,
(
10
,
10
,
10
))
src
=
fslimage
.
Image
(
srcdata
)
ref
=
fslimage
.
Image
(
refdata
,
xform
=
src2ref
)
field
=
_affine_field
(
src
,
ref
,
ref2src
,
'
world
'
,
'
world
'
)
altrefxform
=
affine
.
concat
(
src2ref
,
affine
.
scaleOffsetXform
([
1
,
1
,
1
],
[
5
,
0
,
0
]))
altref
=
fslimage
.
Image
(
refdata
,
xform
=
altrefxform
)
expect
,
xf
=
resample
.
resampleToReference
(
src
,
altref
,
matrix
=
src2ref
,
order
=
1
,
mode
=
'
constant
'
,
cval
=
0
)
result
=
nonlinear
.
applyDeformation
(
src
,
field
,
ref
=
altref
,
order
=
1
,
mode
=
'
constant
'
,
cval
=
0
)
# We can get imprecision/rounding errors
# which may cause affine_transform and
# map_coordinates to determine that
# boundary voxels are out of bounds
expect
=
expect
[
1
:
-
1
,
1
:
-
1
,
1
:
-
1
]
result
=
result
[
1
:
-
1
,
1
:
-
1
,
1
:
-
1
]
assert
np
.
all
(
np
.
isclose
(
expect
,
result
))
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