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
f860d0ef
Commit
f860d0ef
authored
5 years ago
by
Paul McCarthy
Browse files
Options
Downloads
Patches
Plain Diff
TEST: Test new resample options
parent
d503ec72
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_image.py
+46
-0
46 additions, 0 deletions
tests/test_image.py
with
46 additions
and
0 deletions
tests/test_image.py
+
46
−
0
View file @
f860d0ef
...
...
@@ -1186,6 +1186,52 @@ def test_image_resample_4d(seed):
resampled
=
None
def
test_Image_resample_offset
(
seed
):
with
tempdir
()
as
td
:
fname
=
op
.
join
(
td
,
'
test.nii
'
)
make_random_image
(
fname
,
(
10
,
10
,
10
))
img
=
fslimage
.
Image
(
fname
)
# with origin='corner', image
# bounding boxes should match
for
i
in
range
(
25
):
shape
=
np
.
random
.
randint
(
5
,
50
,
3
)
res
=
img
.
resample
(
shape
,
origin
=
'
corner
'
)
res
=
fslimage
.
Image
(
res
[
0
],
xform
=
res
[
1
])
imgb
=
transform
.
axisBounds
(
img
.
shape
,
img
.
voxToWorldMat
)
resb
=
transform
.
axisBounds
(
res
.
shape
,
res
.
voxToWorldMat
)
assert
np
.
all
(
np
.
isclose
(
imgb
,
resb
,
rtol
=
1e-5
,
atol
=
1e-5
))
# with origin='centre' image
# bounding boxes should be offset
# by (size_resampled - size_orig) / 2
for
i
in
range
(
25
):
shape
=
np
.
random
.
randint
(
5
,
50
,
3
)
res
=
img
.
resample
(
shape
,
origin
=
'
centre
'
)
res
=
fslimage
.
Image
(
res
[
0
],
xform
=
res
[
1
])
off
=
(
np
.
array
(
img
.
shape
)
/
np
.
array
(
res
.
shape
)
-
1
)
/
2
imgb
=
np
.
array
(
transform
.
axisBounds
(
img
.
shape
,
img
.
voxToWorldMat
))
resb
=
np
.
array
(
transform
.
axisBounds
(
res
.
shape
,
res
.
voxToWorldMat
))
assert
np
.
all
(
np
.
isclose
(
imgb
,
resb
+
off
,
rtol
=
1e-5
,
atol
=
1e-5
))
# with origin='corner', using
# linear interp, when we down-
# sample an image to a shape
# that divides evenly into the
# original shape, a downsampled
# voxel should equal the average
# of the original voxels inside
# it.
res
=
img
.
resample
((
5
,
5
,
5
),
smooth
=
False
,
origin
=
'
corner
'
)[
0
]
for
x
,
y
,
z
in
it
.
product
(
range
(
5
),
range
(
5
),
range
(
5
)):
block
=
img
[
x
*
2
:
x
*
2
+
2
,
y
*
2
:
y
*
2
+
2
,
z
*
2
:
z
*
2
+
2
]
assert
np
.
isclose
(
res
[
x
,
y
,
z
],
block
.
mean
())
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
):
...
...
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