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
cef8879e
Commit
cef8879e
authored
8 years ago
by
Paul McCarthy
Browse files
Options
Downloads
Patches
Plain Diff
More tests
parent
f2b731a0
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.py
+115
-2
115 additions, 2 deletions
tests/test_image.py
tests/test_imagewrapper.py
+1
-1
1 addition, 1 deletion
tests/test_imagewrapper.py
tests/test_transform.py
+47
-0
47 additions, 0 deletions
tests/test_transform.py
with
163 additions
and
3 deletions
tests/test_image.py
+
115
−
2
View file @
cef8879e
...
@@ -10,8 +10,9 @@ import os.path as op
...
@@ -10,8 +10,9 @@ import os.path as op
import
pytest
import
pytest
import
glob
import
glob
import
numpy
as
np
import
numpy
as
np
import
nibabel
as
nib
import
numpy.linalg
as
npla
import
nibabel
as
nib
from
nibabel.spatialimages
import
ImageFileError
from
nibabel.spatialimages
import
ImageFileError
...
@@ -201,6 +202,118 @@ def test_Image_sqforms(testdir):
...
@@ -201,6 +202,118 @@ def test_Image_sqforms(testdir):
assert
np
.
all
(
np
.
isclose
(
noqform
.
worldToVoxMat
,
benchmark
.
worldToVoxMat
))
assert
np
.
all
(
np
.
isclose
(
noqform
.
worldToVoxMat
,
benchmark
.
worldToVoxMat
))
assert
np
.
all
(
np
.
isclose
(
nosqform
.
voxToWorldMat
,
scalemat
))
assert
np
.
all
(
np
.
isclose
(
nosqform
.
voxToWorldMat
,
scalemat
))
assert
np
.
all
(
np
.
isclose
(
nosqform
.
worldToVoxMat
,
invScalemat
))
assert
np
.
all
(
np
.
isclose
(
nosqform
.
worldToVoxMat
,
invScalemat
))
assert
benchmark
.
getXFormCode
()
==
constants
.
NIFTI_XFORM_MNI_152
assert
benchmark
.
getXFormCode
(
'
sform
'
)
==
constants
.
NIFTI_XFORM_MNI_152
assert
benchmark
.
getXFormCode
(
'
qform
'
)
==
constants
.
NIFTI_XFORM_MNI_152
assert
nosform
.
getXFormCode
()
==
constants
.
NIFTI_XFORM_MNI_152
assert
nosform
.
getXFormCode
(
'
sform
'
)
==
constants
.
NIFTI_XFORM_UNKNOWN
assert
nosform
.
getXFormCode
(
'
qform
'
)
==
constants
.
NIFTI_XFORM_MNI_152
assert
noqform
.
getXFormCode
()
==
constants
.
NIFTI_XFORM_MNI_152
assert
noqform
.
getXFormCode
(
'
sform
'
)
==
constants
.
NIFTI_XFORM_MNI_152
assert
noqform
.
getXFormCode
(
'
qform
'
)
==
constants
.
NIFTI_XFORM_UNKNOWN
assert
nosqform
.
getXFormCode
()
==
constants
.
NIFTI_XFORM_UNKNOWN
assert
nosqform
.
getXFormCode
(
'
sform
'
)
==
constants
.
NIFTI_XFORM_UNKNOWN
assert
nosqform
.
getXFormCode
(
'
qform
'
)
==
constants
.
NIFTI_XFORM_UNKNOWN
def
test_Image_changeXform
(
testdir
):
img
=
fslimage
.
Image
(
op
.
join
(
testdir
,
'
MNI152_T1_2mm.nii.gz
'
))
notified
=
{}
def
onXform
(
*
a
):
notified
[
'
xform
'
]
=
True
def
onSave
(
*
a
):
notified
[
'
save
'
]
=
True
img
.
register
(
'
name1
'
,
onXform
,
'
transform
'
)
img
.
register
(
'
name2
'
,
onSave
,
'
saveState
'
)
newXform
=
np
.
array
([[
5
,
0
,
0
,
10
],
[
0
,
2
,
0
,
23
],
[
0
,
0
,
14
,
5
],
[
0
,
0
,
0
,
1
]])
assert
img
.
saveState
img
.
voxToWorldMat
=
newXform
invx
=
npla
.
inv
(
newXform
)
assert
notified
.
get
(
'
xform
'
,
False
)
assert
notified
.
get
(
'
save
'
,
False
)
assert
not
img
.
saveState
assert
np
.
all
(
np
.
isclose
(
img
.
voxToWorldMat
,
newXform
))
assert
np
.
all
(
np
.
isclose
(
img
.
worldToVoxMat
,
invx
))
def
test_Image_changeData
(
testdir
):
img
=
fslimage
.
Image
(
op
.
join
(
testdir
,
'
dtypes
'
,
'
MNI152_T1_1mm_float.nii.gz
'
))
notified
=
{}
def
randvox
():
return
(
np
.
random
.
randint
(
0
,
img
.
shape
[
0
]),
np
.
random
.
randint
(
0
,
img
.
shape
[
1
]),
np
.
random
.
randint
(
0
,
img
.
shape
[
2
]))
def
onData
(
*
a
):
notified
[
'
data
'
]
=
True
def
onSaveState
(
*
a
):
notified
[
'
save
'
]
=
True
def
onDataRange
(
*
a
):
notified
[
'
dataRange
'
]
=
True
img
.
register
(
'
name1
'
,
onData
,
'
data
'
)
img
.
register
(
'
name2
'
,
onSaveState
,
'
saveState
'
)
img
.
register
(
'
name3
'
,
onDataRange
,
'
dataRange
'
)
data
=
img
.
nibImage
.
get_data
()
dmin
=
data
.
min
()
dmax
=
data
.
max
()
drange
=
dmax
-
dmin
assert
img
.
saveState
assert
np
.
all
(
np
.
isclose
(
img
.
dataRange
,
(
dmin
,
dmax
)))
randval
=
dmin
+
np
.
random
.
random
()
*
drange
rx
,
ry
,
rz
=
randvox
()
img
[
rx
,
ry
,
rz
]
=
randval
assert
np
.
isclose
(
img
[
rx
,
ry
,
rz
],
randval
)
assert
notified
.
get
(
'
data
'
,
False
)
assert
notified
.
get
(
'
save
'
,
False
)
assert
not
img
.
saveState
notified
.
pop
(
'
data
'
)
newdmin
=
dmin
-
100
newdmax
=
dmax
+
100
rx
,
ry
,
rz
=
randvox
()
img
[
rx
,
ry
,
rz
]
=
newdmin
assert
notified
.
get
(
'
data
'
,
False
)
assert
notified
.
get
(
'
dataRange
'
,
False
)
assert
np
.
isclose
(
img
[
rx
,
ry
,
rz
],
newdmin
)
assert
np
.
all
(
np
.
isclose
(
img
.
dataRange
,
(
newdmin
,
dmax
)))
notified
.
pop
(
'
data
'
)
notified
.
pop
(
'
dataRange
'
)
rx
,
ry
,
rz
=
randvox
()
img
[
rx
,
ry
,
rz
]
=
newdmax
assert
notified
.
get
(
'
data
'
,
False
)
assert
notified
.
get
(
'
dataRange
'
,
False
)
assert
np
.
isclose
(
img
[
rx
,
ry
,
rz
],
newdmax
)
assert
np
.
all
(
np
.
isclose
(
img
.
dataRange
,
(
newdmin
,
newdmax
)))
def
test_2D_images
(
testdir
):
def
test_2D_images
(
testdir
):
...
...
This diff is collapsed.
Click to expand it.
tests/test_imagewrapper.py
+
1
−
1
View file @
cef8879e
...
@@ -244,7 +244,7 @@ def coverageDataRange(data, coverage, slices=None):
...
@@ -244,7 +244,7 @@ def coverageDataRange(data, coverage, slices=None):
sliceobj
=
[]
sliceobj
=
[]
for
d
in
range
(
ndims
):
for
d
in
range
(
ndims
):
sliceobj
.
append
(
slice
(
cov
[
0
,
d
],
cov
[
1
,
d
],
1
))
sliceobj
.
append
(
slice
(
int
(
cov
[
0
,
d
]
)
,
int
(
cov
[
1
,
d
]
)
,
1
))
sliceobj
.
append
(
vol
)
sliceobj
.
append
(
vol
)
voldata
=
data
[
tuple
(
sliceobj
)]
voldata
=
data
[
tuple
(
sliceobj
)]
...
...
This diff is collapsed.
Click to expand it.
tests/test_transform.py
0 → 100644
+
47
−
0
View file @
cef8879e
#!/usr/bin/env python
#
# test_transform.py -
#
# Author: Paul McCarthy <pauldmccarthy@gmail.com>
#
import
numpy
as
np
import
numpy.linalg
as
npla
import
fsl.utils.transform
as
transform
def
test_scaleOffsetXform
():
scales
=
[
1
,
2
,
3
]
offsets
=
[
4
,
5
,
6
]
expected
=
np
.
eye
(
4
)
expected
[
0
,
0
]
=
scales
[
0
]
expected
[
1
,
1
]
=
scales
[
1
]
expected
[
2
,
2
]
=
scales
[
2
]
expected
[
0
,
3
]
=
offsets
[
0
]
expected
[
1
,
3
]
=
offsets
[
1
]
expected
[
2
,
3
]
=
offsets
[
2
]
generated
=
transform
.
scaleOffsetXform
(
scales
,
offsets
)
assert
np
.
all
(
np
.
isclose
(
expected
,
generated
))
scale
=
5
offset
=
3
expected
=
np
.
eye
(
4
)
expected
[
0
,
0
]
=
scale
expected
[
1
,
1
]
=
1
expected
[
2
,
2
]
=
1
expected
[
2
,
2
]
=
1
expected
[
0
,
3
]
=
offset
generated
=
transform
.
scaleOffsetXform
(
scale
,
offset
)
assert
np
.
all
(
np
.
isclose
(
expected
,
generated
))
def
test_invert
():
pass
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