-
Notifications
You must be signed in to change notification settings - Fork 270
NF: Conformation function and CLI tool to apply shape, orientation and zooms #853
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 6 commits
b897935
76e9aed
9895eb0
49e4ada
57c3648
a681bdd
4e62b7c
e19b022
12ea136
89eedc5
348f838
9491806
a9ce73b
3911610
0d8843b
3e4da11
8b712ca
67ace2f
527400d
6e19298
07fa254
00825c7
4ca32ba
a536ed3
3af4bd8
3658170
eb097f4
241f58f
f77fbb5
2177a59
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,10 +19,11 @@ | |
|
|
||
| import nibabel as nib | ||
| from nibabel.processing import (sigma2fwhm, fwhm2sigma, adapt_affine, | ||
| resample_from_to, resample_to_output, smooth_image) | ||
| resample_from_to, resample_to_output, smooth_image, | ||
| _transform_range, conform) | ||
| from nibabel.nifti1 import Nifti1Image | ||
| from nibabel.nifti2 import Nifti2Image | ||
| from nibabel.orientations import flip_axis, inv_ornt_aff | ||
| from nibabel.orientations import aff2axcodes, flip_axis, inv_ornt_aff | ||
| from nibabel.affines import (AffineError, from_matvec, to_matvec, apply_affine, | ||
| voxel_sizes) | ||
| from nibabel.eulerangles import euler2mat | ||
|
|
@@ -426,3 +427,33 @@ def test_against_spm_resample(): | |
| moved2output = resample_to_output(moved_anat, 4, order=1, cval=np.nan) | ||
| spm2output = nib.load(pjoin(DATA_DIR, 'reoriented_anat_moved.nii')) | ||
| assert_spm_resampling_close(moved_anat, moved2output, spm2output); | ||
|
|
||
|
|
||
| def test__transform_range(): | ||
| assert_array_equal(_transform_range([2, 4, 6], -1, 1), [-1, 0, 1]) | ||
| assert_array_equal(_transform_range([-1, 0, 1], 2, 6), [2, 4, 6]) | ||
| assert_array_equal(_transform_range(np.arange(11), 0, 5), | ||
| np.arange(0, 5.5, 0.5)) | ||
| assert_array_equal(_transform_range(np.arange(-100, 101), 0, 200), | ||
| np.arange(201)) | ||
|
|
||
|
|
||
| @needs_scipy | ||
| def test_conform(): | ||
| anat = nib.load(pjoin(DATA_DIR, 'anatomical.nii')) | ||
|
|
||
| c = conform(anat) | ||
| assert c.shape == (256, 256, 256) | ||
| assert c.header.get_zooms() == (1, 1, 1) | ||
| assert c.dataobj.dtype == np.dtype(np.uint8) | ||
| assert aff2axcodes(c.affine) == ('R', 'A', 'S') | ||
|
|
||
| c = conform(anat, out_shape=(100, 100, 200), voxel_size=(2, 2, 1.5)) | ||
| assert c.shape == (100, 100, 200) | ||
| assert c.header.get_zooms() == (2, 2, 1.5) | ||
| assert c.dataobj.dtype == np.dtype(np.uint8) | ||
| assert aff2axcodes(c.affine) == ('R', 'A', 'S') | ||
|
|
||
| # Error on non-3D images. | ||
|
||
| func = nib.load(pjoin(DATA_DIR, 'functional.nii')) | ||
| assert_raises(ValueError, conform, func) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should it become resilient to
x_max == x_minwhen it would either set it tonew_minor blow some better than ZeroDivisonError exception?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thank you @yarikoptic - i will account for
x_max == x_minand i will add a test for this case.