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
Model registry
Operate
Environments
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
FSL
fslpy
Commits
eb1d12ec
Commit
eb1d12ec
authored
7 years ago
by
Paul McCarthy
Browse files
Options
Downloads
Patches
Plain Diff
Transform module testing complete
parent
d6b24a75
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
tests/test_transform.py
+51
-0
51 additions, 0 deletions
tests/test_transform.py
tests/testdata/test_transform_test_flirtMatrixToSform.txt
+83
-0
83 additions, 0 deletions
tests/testdata/test_transform_test_flirtMatrixToSform.txt
with
134 additions
and
0 deletions
tests/test_transform.py
+
51
−
0
View file @
eb1d12ec
...
...
@@ -13,6 +13,7 @@ import numpy as np
import
pytest
import
fsl.utils.transform
as
transform
import
fsl.data.image
as
fslimage
datadir
=
op
.
join
(
op
.
dirname
(
__file__
),
'
testdata
'
)
...
...
@@ -253,3 +254,53 @@ def test_transform():
with
pytest
.
raises
(
ValueError
):
transform
.
transform
(
badcoords
[:,
(
1
,
2
,
3
)],
xform
,
axes
=
[
1
,
2
])
def
test_flirtMatrixToSform
():
testfile
=
op
.
join
(
datadir
,
'
test_transform_test_flirtMatrixToSform.txt
'
)
lines
=
readlines
(
testfile
)
ntests
=
len
(
lines
)
/
18
for
i
in
range
(
ntests
):
tlines
=
lines
[
i
*
18
:
i
*
18
+
18
]
srcShape
=
[
int
(
w
)
for
w
in
tlines
[
0
].
split
()]
srcXform
=
np
.
genfromtxt
(
tlines
[
1
:
5
])
refShape
=
[
int
(
w
)
for
w
in
tlines
[
5
].
split
()]
refXform
=
np
.
genfromtxt
(
tlines
[
6
:
10
])
flirtMat
=
np
.
genfromtxt
(
tlines
[
10
:
14
])
expected
=
np
.
genfromtxt
(
tlines
[
14
:
18
])
srcImg
=
fslimage
.
Image
(
np
.
zeros
(
srcShape
),
xform
=
srcXform
)
refImg
=
fslimage
.
Image
(
np
.
zeros
(
refShape
),
xform
=
refXform
)
result
=
transform
.
flirtMatrixToSform
(
flirtMat
,
srcImg
,
refImg
)
assert
np
.
all
(
np
.
isclose
(
result
,
expected
))
def
test_sformToFlirtMatrix
():
testfile
=
op
.
join
(
datadir
,
'
test_transform_test_flirtMatrixToSform.txt
'
)
lines
=
readlines
(
testfile
)
ntests
=
len
(
lines
)
/
18
for
i
in
range
(
ntests
):
tlines
=
lines
[
i
*
18
:
i
*
18
+
18
]
srcShape
=
[
int
(
w
)
for
w
in
tlines
[
0
].
split
()]
srcXform
=
np
.
genfromtxt
(
tlines
[
1
:
5
])
refShape
=
[
int
(
w
)
for
w
in
tlines
[
5
].
split
()]
refXform
=
np
.
genfromtxt
(
tlines
[
6
:
10
])
expected
=
np
.
genfromtxt
(
tlines
[
10
:
14
])
srcXformOvr
=
np
.
genfromtxt
(
tlines
[
14
:
18
])
srcImg1
=
fslimage
.
Image
(
np
.
zeros
(
srcShape
),
xform
=
srcXform
)
srcImg2
=
fslimage
.
Image
(
np
.
zeros
(
srcShape
),
xform
=
srcXform
)
refImg
=
fslimage
.
Image
(
np
.
zeros
(
refShape
),
xform
=
refXform
)
srcImg2
.
voxToWorldMat
=
srcXformOvr
result1
=
transform
.
sformToFlirtMatrix
(
srcImg1
,
refImg
,
srcXformOvr
)
result2
=
transform
.
sformToFlirtMatrix
(
srcImg2
,
refImg
)
assert
np
.
all
(
np
.
isclose
(
result1
,
expected
))
assert
np
.
all
(
np
.
isclose
(
result2
,
expected
))
This diff is collapsed.
Click to expand it.
tests/testdata/test_transform_test_flirtMatrixToSform.txt
0 → 100644
+
83
−
0
View file @
eb1d12ec
# Test data for test_trasform:test_flirtMatrixToSform.
#
# Source shape
# Source sform
# Ref shape
# Ref sform
# Flirt mat
# Expected result
64 64 51
-3 0 0 0
0 3 0 0
0 0 3 0
0 0 0 1
174 192 192
-1 0 0 0
0 1 0 0
0 0 1 0
0 0 0 1
0.999902305 -0.01382370227 -0.002076008527 -9.96418133
0.01387598986 0.9995186947 0.02774033918 -0.9784486659
0.001691535807 -0.02776642771 0.999613178 34.26763376
0 0 0 1
-2.9997069836 0.0414711051 0.0062280255 9.9641809464
0.0416279696 2.9985561371 0.0832210183 -0.978448689
0.0050746072 -0.0832992867 2.9988396168 34.2676353455
0.0 0.0 0.0 1.0
64 64 51
-3 0 0 0
0 3 0 0
0 0 3 0
0 0 0 1
91 109 91
-2.0 0.0 -0.0 90.0
0.0 2.0 -0.0 -126.0
0.0 0.0 2.0 -72.0
0.0 0.0 0.0 1.0
1.066596657 0.04185305106 0.0313680447 -21.01545453
-0.0278838133 1.08492943 0.1200141384 3.254608605
-0.02264077087 -0.1506102631 1.159656209 14.04435425
0 0 0 1
-3.1997900009 -0.1255591512 -0.0941041335 111.0154571533
-0.0836514384 3.2547883987 0.360042423 -122.7453918457
-0.067922309 -0.4518307745 3.4789686203 -57.9556465149
0.0 0.0 0.0 1.0
96 96 65
-2 0 0 0
0 2 0 0
0 0 2 0
0 0 0 1
182 218 182
-1.0 0.0 -0.0 90.0
0.0 1.0 -0.0 -126.0
0.0 0.0 1.0 -72.0
0.0 0.0 0.0 1.0
0.9770925311 0.2282763526 0.08361742115 -31.03359277
-0.2174139321 1.034970829 0.2368454135 21.28393351
-0.03214544114 -0.1330475704 1.107802568 23.65687239
0 0 0 1
-1.954185009 -0.4565527141 -0.167234838 121.0335922241
-0.4348278642 2.0699417591 0.4736908376 -104.7160644531
-0.0642908812 -0.2660951316 2.2156050205 -48.3431282043
0.0 0.0 0.0 1.0
64 64 21
-4 0 0 0
0 4 0 0
0 0 6 0
0 0 0 1
256 256 128
-1.0 0.0 0.0 0.0
0.0 1.0 0.0 0.0
0.0 0.0 1.25 0.0
0.0 0.0 0.0 1.0
1.04608 -0.0092732 -0.0230782 -3.88992
0.00607773 1.01145 0.105602 -3.84974
0.0244433 -0.0793108 1.05191 15.932
0 0 0 1
-4.184319973 0.0370928012 0.1384692043 3.8899199963
0.0243109204 4.045800209 0.6336119771 -3.8497400284
0.0977732018 -0.3172431886 6.3114600182 15.9320001602
0.0 0.0 0.0 1.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