8000 ENH,WIP: New transforms module by oesteban · Pull Request #656 · nipy/nibabel · GitHub
[go: up one dir, main page]

Skip to content

ENH,WIP: New transforms module #656

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

Closed
wants to merge 36 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
3cfff0d
ENH: Add an utility to calculate obliquity of affines
oesteban Sep 20, 2019
c92d560
enh(tests): add not-oblique test, move tests to ``test_affines.py``
oesteban Sep 20, 2019
da8da56
enh: return radians unless degrees=True
oesteban Sep 22, 2019
253a256
enh: address @matthew-brett's comments
oesteban Sep 23, 2019
04584b6
doc: add link to AFNI's documentation about *obliquity* [skip ci]
oesteban Sep 24, 2019
70d9620
Initial commit
oesteban Aug 1, 2018
36a1764
add TransformBase
oesteban Aug 1, 2018
2a700c9
add new module
oesteban Aug 1, 2018
fda2bfe
add documentation, core functionality
oesteban Aug 1, 2018
3ef5adc
add a deformation field transform
oesteban Aug 1, 2018
189a662
optimize deformation field
oesteban Aug 2, 2018
2619ae4
pre-cache transformed indexes
oesteban Aug 2, 2018
4e7c19b
used cached field
oesteban Aug 2, 2018
23d7002
add caching of deltas in voxel coordinates
oesteban Aug 3, 2018
2acd9f3
add bspline cython extension
oesteban Aug 3, 2018
385ceff
a smarter ImageSpace
oesteban Aug 4, 2018
fa030a4
add comment
oesteban Aug 10, 2018
fd418fe
remove cython module
oesteban Aug 10, 2018
13d722f
cleanup
oesteban Aug 11, 2018
253aed5
starting with bspline transform
oesteban Aug 11, 2018
47c2a57
finishing b-spline interpolation
oesteban Aug 13, 2018
4478c06
Add base implementation of transforms and change base implementation …
oesteban Mar 12, 2019
99fa15d
export to hdf5
oesteban Mar 13, 2019
5eed01d
corrections to adhere the current x5 format draft
oesteban Mar 14, 2019
632e068
fix coordinates translation in affines, import itk affines
oesteban Mar 15, 2019
f2c062e
wip: reads & writes ITK's MatrixOffsetTransformBase transforms, with …
oesteban Mar 16, 2019
8eb670d
fix: print warnings to stderr, sty: minimal fixes
oesteban Mar 16, 2019
799fb6e
enh(affines): write out AFNI 12-parameters files
oesteban Mar 19, 2019
ce36f06
enh(transforms): finish up a x5-to-fsl writer of affines
oesteban Mar 21, 2019
8e1bf44
enh(transforms): improve generation of x5 structures of reference spaces
oesteban Mar 21, 2019
e2df7cc
fix(transforms): string formating forgotten when writing ITK transforms
oesteban Mar 22, 2019
c5d10ed
wip(transforms): writing up some linear transform readers
oesteban Mar 22, 2019
a18ce1d
enh(transform): HDF5 - set values as attributes; generalize affines t…
oesteban Mar 22, 2019
9902f50
enh: apply some early comments from @effigies.
oesteban Sep 19, 2019
fe74efb
fix: add a first battery of tests
oesteban Sep 26, 2019
596994c
enh: add tests for affines stored in AFNI format (non-oblique images)
oesteban Sep 27, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add bspline cython extension
  • Loading branch information
oesteban committed Sep 27, 2019
commit 2acd9f39c4500181ef5c52c238bcd880d0cd1f29
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,4 @@ Thumbs.db
doc/source/reference
venv/
.buildbot.patch
nibabel/maths/bspline.c
17 changes: 17 additions & 0 deletions nibabel/maths/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# emacs: -*- mode: python-mode; py-indent-offset: 4; indent-tabs-mode: nil -*-
# vi: set ft=python sts=4 ts=4 sw=4 et:
### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ##
#
# See COPYING file distributed along with the NiBabel package for the
# copyright and license terms.
#
### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ##
"""Geometric transforms

.. currentmodule:: nibabel.maths

.. autosummary::
:toctree: ../generated

maths
"""
43 changes: 43 additions & 0 deletions nibabel/maths/bspline.pyx
8000
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# emacs: -*- mode: python-mode; py-indent-offset: 4; indent-tabs-mode: nil -*-
# vi: set ft=python sts=4 ts=4 sw=4 et:
### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ##
#
# See COPYING file distributed along with the NiBabel package for the
# copyright and license terms.
#
### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ##
''' Cython math extension '''
from __future__ import division
import numpy as np
cimport numpy as np
cimport cython
from libc.math cimport fabs


cdef double c_cubic(double x) nogil:
cdef:
double x_t = fabs(x)

if x_t >= 2.0:
return(0.0)
if x_t <= 1.0:
return(2.0 / 3.0 - x_t**2 + 0.5 * x_t**3)
elif x_t <= 2.0:
return((2 - x_t)**3 / 6.0)


def cubic(double x):
"""
Evaluate the univariate cubic bspline at x

Pure python implementation: ::

def bspl(x):
if x >= 2.0:
return 0.0
if x <= 1.0:
return 2.0 / 3.0 - x**2 + 0.5 * x**3
elif x <= 2.0:
return (2 - x)**3 / 6.0
"""
return(c_cubic(x))
28 changes: 28 additions & 0 deletions nibabel/transform/nonlinear.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,31 @@ def resample(self, moving, order=3, mode='constant', cval=0.0, prefilter=True,

def map_voxel(self, index, moving=None):
return tuple(self._moving[index + self.__s])

def map_coordinates(self, coordinates, order=3, mode='constant', cval=0.0,
prefilter=True):
coordinates = np.array(coordinates)
# Extract shapes and dimensions, then flatten
ndim = coordinates.shape[-1]
output_shape = coordinates.shape[:-1]
flatcoord = np.moveaxis(coordinates, -1, 0).reshape(ndim, -1)

# Convert coordinates to voxel indices
ijk = np.tensordot(
np.linalg.inv(self.reference.affine),
np.vstack((flatcoord, np.ones((1, flatcoord.shape[1])))),
axes=1)
deltas = ndi.map_coordinates(
self._field,
ijk,
order=order,
mode=mode,
cval=cval,
prefilter=prefilter)

print(deltas)

deltas = np.moveaxis(deltas[0:3, :].reshape((ndim, ) + output_shape),
0, -1)

return coordinates + deltas
0