-
Notifications
You must be signed in to change notification settings - Fork 260
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
MRG: add resampling and smoothing functions #255
Conversation
I would very much like a review here - anyone? |
* resampling | ||
* converting sd to and from FWHM | ||
|
||
Smoothing and resampling routines need scipy |
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 any docs be updated to mention this? Not sure what nibabel
doc building / standards are like.
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.
I would like to leave this out of the docs for now, to avoid people hitting the problem with unspecified axes.
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.
You mean leave the resampling functions out entirely, until support is more complete? Fine by me.
Other than my comments and the fact that this needs a rebase LGTM. You might want to have someone else take a look, though, since I'm not yet too familiar with these operations. |
My remaining problem with this PR is that it assumes that the fourth dimension of the image is special, or, more, it assumes the first three dimensions are spatial. This isn't true for MINC for example, and I haven't decided yet whether this should be a requirement for nibabel images.
I have thought about adding an |
That seems reasonable. Might be even more useful to have something like |
02db779
to
a62c841
Compare
@matthew-brett do you think you'll have time to take these up again soon? We don't have to if there are other priorities, but my memory traces from the visualization PR / branch get increasingly lost in my head as time passes :) |
Thanks for the reminder. Still stalled for lack of courage for thinking about the I guess it is time for a BIAP : https://github.com/nipy/nibabel/wiki |
I believe this was covered here: https://github.com/nipy/nibabel/wiki/BIAP6 I think the general solution is best: https://github.com/nipy/nibabel/wiki/BIAP6#general-solution-associating-axes-and-labels . Seems there are a number of other image formats people are interested to integrate; this solution seems to give the most flexibility for dealing with implementation-specific details of new image formats. |
☔ The latest upstream changes (presumably #402) made this pull request unmergeable. Please resolve the merge conflicts. |
Change append_diag to use AffineError
Moving the parameters to a function allows me to use the same parameters for testing the resample_to_output function (coming soon to a repo near you).
Add: * resampling images to images / mapped voxels * resampling images to output space * smoothing over voxel axes * FWHM / sigma conversion
From review by Eric L.
Fix docstring giving wrong explanation for ND interpolation.
f1f0789
to
a9e1900
Compare
This PR is old now, and I think it's time to merge and see what folks make of it. Any other comments here before I go ahead? The axis stuff should get done before a release, surely, but let's get this in for now. |
Other than the idea of comparing to the output of another program for validation LGTM. That could be a separate PR, too, if necessary. |
Eric - yes - sorry - that is a good idea. For convenience, I'm planning to use the anatomical and function from here: https://github.com/nipy/nipy/tree/master/nipy/testing - and reslice them using using an arbitrary transformation using SPM. Sound reasonable? |
Sounds good to me
|
Hmm - this is proving unpleasant. If you're interested, you can have a look at the failing test on this branch here : https://github.com/matthew-brett/nibabel/tree/tmp-processing . There are some voxels that are way off on the boundary of the image. I have a vague memory that Omar Ocuegueda hit this from the scipy resample routines. I'm afraid this may need some serious thought. |
Test error here - https://travis-ci.org/matthew-brett/nibabel/jobs/110700306#L1056 |
The discussion I was thinking of is: |
We're getting almost exactly the same as |
It is a problem of interpolating outside the image boundary, but in fact I think this isn't a serious problem for us (though it makes it harder to test properly). Here's the script that reproduces the problem: https://gist.github.com/77a3dd12998755ad3259 The points giving the big differences have the following coordinates in the resampling-from image:
So, both are sampling just outside the volume (<0, >40) and therefore the sampling is returning 0. Just setting these values to 0, 40, brings these back to the boundary, and gives real image values:
Even a tiny change flips the value to outside the volume, and resampled value of 0:
Now going over to SPM - we load the points (1-based indexing corrected):
We get the SPM equivalent of an image object, and sample at these points:
This is the difference between the nibabel and SPM resampling. In fact, what is happening is that the resampling goes to zero when any of the coordinates are > 0.05 voxel units outside the image border:
I think this comes from these lines of the SPM code: https://bitbucket.org/matthewbrett/spm-versions/src/ac51a22a558771288241e54b48d3e8420d2585ca/spm12/src/spm_vol_utils.c?at=master&fileviewer=file-view-default#spm_vol_utils.c-403 The code is checking if the voxel is > TINY units outside the boundary, where TINY turns out to be 0.05 (https://bitbucket.org/matthewbrett/spm-versions/src/ac51a22a558771288241e54b48d3e8420d2585ca/spm12/src/spm_vol_utils.c?at=master&fileviewer=file-view-default#spm_vol_utils.c-6) So, I think these differences are an artefact of how SPM does its interpolation, and we're probably OK. |
Looks like you have a good handle on the differences in implementation. Maybe it's good enough note in the doc that there can be serious differences in the results at the boundaries? |
Thinking about it with the benefit of a bit more sleep, I think I will use the calculations above to allow the differences in the points that go very slightly off the edge, PR soon, finishing this off, probably Wednesday. |
Allow user to specify a scalar meaning that voxel sizes for each dimension of the image should be the same.
Allow rtol, atol for wrapper around ``allclose``.
OK - I added the tests against SPM resampling, ready for review. |
8514156
to
fa17e8d
Compare
Build some test images by resampling with SPM, and test our resampling against SPM's resampling.
fa17e8d
to
054e20c
Compare
LGTM |
MRG: add resampling and smoothing functions This pull request adds some simple processing functions when scipy is available. The functions are: * resample_from_to - resample first image into space of second * resample_to_output - resample image into output (world) space * smooth_image - smooth image over voxel axes I also put in the utility functions converting between FWHM and sigma.
MRG: add resampling and smoothing functions This pull request adds some simple processing functions when scipy is available. The functions are: * resample_from_to - resample first image into space of second * resample_to_output - resample image into output (world) space * smooth_image - smooth image over voxel axes I also put in the utility functions converting between FWHM and sigma.
This pull request adds some simple processing functions when scipy
is available. The functions are:
I also put in the utility functions converting between FWHM and sigma.