antsx / antspy Goto Github PK
View Code? Open in Web Editor NEWA fast medical imaging analysis library in Python with algorithms for registration, segmentation, and more.
Home Page: https://antspyx.readthedocs.io
License: Apache License 2.0
A fast medical imaging analysis library in Python with algorithms for registration, segmentation, and more.
Home Page: https://antspyx.readthedocs.io
License: Apache License 2.0
I find that the registration result is not so stable that in some case the registration stop very fast and the results are not good enough.
I have tried to tune 'reg_iterations' and 'grad_step' parameters in 'ants.registration' function but it didn't help.
Is there any option in 'antspy' or 'ants' to disable the early stopping of optimizer during registration?
Any help would be much appreciated !
It looks like the newest wheel on pypi is a bit stale: https://pypi.org/project/antspy/#history
When reading an image, an error is returned because short data types are not a supported data type for ANTsPy. Is there a way around this to include compatibility for short data types. Or is there a good way to convert data types from short to a float for example (maybe in ants_image_io.py).
Describe the bug
I tried both functions to visualize brain MRI data, the orientation labels for left and right is opposite to what is shown in ITKSNAP. So, I thought it may be not correct.
To Reproduce
Steps to reproduce the behavior:
image = ants.image_read(path_to_nii)
image.plot_ortho(orient_labels=True) # shown in figure 1
open ITKSNAP and load the nii files, the figure is shown in figure 2
The nifty files are generated by using dcm2niix.
Expected behavior
plot_ortho needs to be consistent with ITKSNAP.
Server (please complete the following information):
I'm trying to import 4D NIFTI file. On this code:
cbf = "file.nii.gz" cbf_img = ants.image_read(cbf, pixeltype='float') cbf_array = cbf_img.numpy()
I'm getting:
Traceback (most recent call last): File "/home/dmitrii/anaconda3/lib/python3.6/site-packages/IPython/core/interactiveshell.py", line 2910, in run_code exec(code_obj, self.user_global_ns, self.user_ns) File "<ipython-input-6-55d262118e20>", line 21, in <module> cbf_img = ants.image_read(cbf, pixeltype='float') File "/home/dmitrii/anaconda3/lib/python3.6/site-packages/ants/core/ants_image_io.py", line 405, in image_read libfn = utils.get_lib_fn(_image_read_dict[pclass][ptype][ndim]) KeyError: 4
Any suggestions how to solve it? Currently using nibabel, works fine.
I am starting to work with ANTsPy and hoping to stay within at least the ANTs world in my code.
I want to reorient a bunch of images to LSP.
I have tested this in ITK-SNAP and the saved output image reopens later in the desired LSP orientation. I have tested this in c3d input.nii -orient LSP -o output.nii and the output image displays in LSP orientation.
Using ANTsPy I have tested:
img = ants.image_read('input.nii')
img = ants.reorient_image2(img,orientation='LSP)
ants.image_write(img,'output.nii')
But when displaying output.nii in ITK-SNAP it still has the original orientation - the image header has changed though.
Am I missing a step to write out the image correctly in LSP when using ANTsPy?
I know I can just use c3d in my code but I wanted to try not to.
Thanks,
Scott
Just curious if this is in the works in the near future? I believe antsR recently added support for this?
Package with great potential, if you could add more examples and tutorials.
Hello, my registration time is too long, could I register with gpu?
thx!!
Hi,
I tried to install the latest release (v0.1.6) on Ubuntu 16.04.4 from binaries through :
pip install https://github.com/ANTsX/ANTsPy/releases/download/v0.1.6/antspy-0.1.6-cp36-cp36m-linux_x86_64.whl
The installation went fine but when trying to import antspy, I run into the following import error :
/lib/x86_64-linux-gnu/libm.so.6: version GLIBC_2.27 not found (required by /home/anaconda/envs/antspy/lib/python3.6/site-packages/ants/lib/antiAlias.cpython-36m-x86_64-linux-gnu.so
(Full traceback at the end of the comment)
I suppose because the code was compiled on Ubuntu 18 with later version of gcc.
My cmake version 3.5.1, gcc version 5.4.0 and I cannot afford to upgrade Ubuntu hence the version of GLIBC.
I tried to build the code from source but ran into another error :
make: *** No target specified and no makefile found
Configuring ANTs core
fatal: target path 'pybind11' already existing and folder is not empty
Configuring ANTsPy library
CMake Error at CMakeLists.txt:10 (find_package):
By not providing "FindITK.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "ITK", but
CMake did not find one.
Could not find a package configuration file provided by "ITK" with any of
the following names:
ITKConfig.cmake
itk-config.cmake
Add the installation prefix of "ITK" to CMAKE_PREFIX_PATH or set "ITK_DIR"
to a directory containing one of the above files. If "ITK" provides a
separate development package or SDK, be sure it has been `installed.`
So i'm left without any option to install antspy for ubuntu 16.04.4, do you have any pointers on anything I could try to install it in one way or another ?
Thank you very much
ImportError Traceback (most recent call last)
<ipython-input-2-9a98c04a2591> in <module>()
5 import os
6
----> 7 from ants import registration
~/anaconda/envs/antspy/lib/python3.6/site-packages/ants/__init__.py in <module>()
5 pass
6
----> 7 from .core import *
8 from .utils import *
9 from .segmentation import *
~/anaconda/envs/antspy/lib/python3.6/site-packages/ants/core/__init__.py in <module>()
1
----> 2 from .ants_image import *
3 from .ants_image_io import *
4
5 from .ants_transform import *
~/anaconda/envs/antspy/lib/python3.6/site-packages/ants/core/ants_image.py in <module>()
25 import inspect
26
---> 27 from .. import utils, registration, segmentation, viz
28 from . import ants_image_io as iio2
29
~/anaconda/envs/antspy/lib/python3.6/site-packages/ants/utils/__init__.py in <module>()
1
----> 2 from .bias_correction import *
3 from .channels import *
4 from .convert_nibabel import *
5 from .crop_image import *
~/anaconda/envs/antspy/lib/python3.6/site-packages/ants/utils/bias_correction.py in <module>()
7
8
----> 9 from . import process_args as pargs
10 from .get_mask import get_mask
11 from .iMath import iMath
~/anaconda/envs/antspy/lib/python3.6/site-packages/ants/utils/process_args.py in <module>()
11
12 from ..core import ants_image as iio
---> 13 from .. import lib
14
15 _short_ptype_map = {'unsigned char' : 'UC',
~/anaconda/envs/antspy/lib/python3.6/site-packages/ants/lib/__init__.py in <module>()
2
3 ## LOCAL ##
----> 4 from .antiAlias import *
5 from .antsImage import *
6 from .antsImageClone import *
ImportError: /lib/x86_64-linux-gnu/libm.so.6: version `GLIBC_2.27' not found (required by /home/parietal/tbazeill/anaconda/envs/antspy/lib/python3.6/site-packages/ants/lib/antiAlias.cpython-36m-x86_64-linux-gnu.so)`
using install method 2 - git clone and python setup.py install
on ubuntu 16.04 clean install i get this error
-- Check the value of the 22nd bit of a 32-bit quiet-NaN - 1
CMake Error at Modules/Bridge/VtkGlue/itk-module-init.cmake:9 (find_package):
Could not find a package configuration file provided by "VTK" with any of
the following names:
VTKConfig.cmake
vtk-config.cmake
Add the installation prefix of "VTK" to CMAKE_PREFIX_PATH or set "VTK_DIR"
to a directory containing one of the above files. If "VTK" provides a
separate development package or SDK, be sure it has been installed.
Call Stack (most recent call first):
CMake/ITKModuleEnablement.cmake:316 (include)
CMakeLists.txt:337 (include)
-- Configuring incomplete, errors occurred!
See also "/home/toddr/Software/ANTsPy/itkbuild/CMakeFiles/CMakeOutput.log".
See also "/home/toddr/Software/ANTsPy/itkbuild/CMakeFiles/CMakeError.log".
make: *** No targets specified and no makefile found. Stop.
Configuring ANTs core
Cloning into 'pybind11'...
remote: Counting objects: 8720, done.
remote: Total 8720 (delta 0), reused 0 (delta 0), pack-reused 8720
Receiving objects: 100% (8720/8720), 2.91 MiB | 0 bytes/s, done.
Resolving deltas: 100% (5855/5855), done.
Checking connectivity... done.
Cloning into 'antsrepo'...
remote: Counting objects: 21016, done.
remote: Compressing objects: 100% (6/6), done.
remote: Total 21016 (delta 1), reused 3 (delta 1), pack-reused 21009
Receiving objects: 100% (21016/21016), 19.06 MiB | 18.85 MiB/s, done.
Resolving deltas: 100% (14515/14515), done.
Checking connectivity... done.
Already on 'master'
Your branch is up-to-date with 'origin/master'.
Already up-to-date.
Note: checking out 'fb874ebe977b84b57b7c5a2b124608f748e8e1e2'.
You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.
If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:
git checkout -b
HEAD is now at fb874eb... ENH: add pixeltype option to resampleImage
Configuring ANTsPy library
-- The C compiler identification is GNU 6.4.0
-- The CXX compiler identification is GNU 6.4.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- The imported target "vtkgdcm" references the file
"/usr/lib/x86_64-linux-gnu/libvtkgdcm.so.2.6.3"
but this file does not exist. Possible reasons include:
-- The imported target "vtkgdcmsharpglue" references the file
"/usr/lib/x86_64-linux-gnu/libvtkgdcmsharpglue.so"
but this file does not exist. Possible reasons include:
-- The imported target "vtkgdcmJava" references the file
"/usr/lib/x86_64-linux-gnu/jni/libvtkgdcmJava.so"
but this file does not exist. Possible reasons include:
-- The imported target "vtkgdcmPython" references the file
"/usr/lib/python/dist-packages/libvtkgdcmPython.so"
but this file does not exist. Possible reasons include:
-- The imported target "vtkgdcmPythonD" references the file
"/usr/lib/x86_64-linux-gnu/libvtkgdcmPythonD.so.2.6.3"
but this file does not exist. Possible reasons include:
CMake Error at CMakeLists.txt:14 (find_package):
By not providing "FindVTK.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "VTK", but
CMake did not find one.
Could not find a package configuration file provided by "VTK" with any of
the following names:
VTKConfig.cmake
vtk-config.cmake
Add the installation prefix of "VTK" to CMAKE_PREFIX_PATH or set "VTK_DIR"
to a directory containing one of the above files. If "VTK" provides a
separate development package or SDK, be sure it has been installed.
-- Configuring incomplete, errors occurred!
See also "/home/toddr/Software/ANTsPy/build/temp.linux-x86_64-2.7/CMakeFiles/CMakeOutput.log".
Traceback (most recent call last):
File "setup.py", line 148, in
classifiers=['Programming Language :: Python :: 3.6'],
File "/home/toddr/Software/anaconda2/lib/python2.7/site-packages/setuptools/init.py", line 129, in setup
return distutils.core.setup(**attrs)
File "/home/toddr/Software/anaconda2/lib/python2.7/distutils/core.py", line 151, in setup
dist.run_commands()
File "/home/toddr/Software/anaconda2/lib/python2.7/distutils/dist.py", line 953, in run_commands
self.run_command(cmd)
File "/home/toddr/Software/anaconda2/lib/python2.7/distutils/dist.py", line 972, in run_command
cmd_obj.run()
File "setup.py", line 53, in run
self.run_command("build_py")
File "/home/toddr/Software/anaconda2/lib/python2.7/distutils/cmd.py", line 326, in run_command
self.distribution.run_command(command)
File "/home/toddr/Software/anaconda2/lib/python2.7/distutils/dist.py", line 972, in run_command
cmd_obj.run()
File "setup.py", line 38, in run
self.run_command("build_ext")
File "/home/toddr/Software/anaconda2/lib/python2.7/distutils/cmd.py", line 326, in run_command
self.distribution.run_command(command)
File "/home/toddr/Software/anaconda2/lib/python2.7/distutils/dist.py", line 972, in run_command
cmd_obj.run()
File "setup.py", line 101, in run
self.build_extension(ext)
File "setup.py", line 130, in build_extension
subprocess.check_call(['cmake', ext.sourcedir] + cmake_args, cwd=self.build_temp, env=env)
File "/home/toddr/Software/anaconda2/lib/python2.7/subprocess.py", line 190, in check_call
raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['cmake', '/home/toddr/Software/ANTsPy/ants/lib', '-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=/home/toddr/Software/ANTsPy/ants/lib/', '-DPYTHON_EXECUTABLE=/home/toddr/Software/anaconda2/bin/python', '-DCMAKE_BUILD_TYPE=Release']' returned non-zero exit status 1
I am analyzing some DTI data, and want to use ANTS (instead of FSL) to warp my results to MNI space. I am trying to find some reference code to make sure I am applying the transforms in the right order.
From what I've read and experimented with, I have done the following.
I used antsRegistrationSynQuick.sh
B0 --> StructT1 (transform_type=r/Rigid)
(Generated Single Affine Matrix)
StructT1-->MNI152_T1_1mm (transform_type=s)
(Generated matrix, Warp and InverseWarp)
I have then been using WarpImageMultiTransform to convert results in B0 Space --> MNI and also tried to warp ROI's in MNI Space --> B0 Space
##Bash Examples
WarpImageMultiTransform 3 $nodifMask nodifMask_to_MNI.nii.gz -R $mni1mm --use-NN $dtiToStructAff $structToMNIAff $structoToMNIwarp
Also looking to do the reverse (i.e. warp the MNI brain to the nodif brain).
WarpImageMultiTransform 3 $mni1mm mni_to_nodif -R $nodif_brain --use-NN $structoToMNIInverseWarp -i $structToMNIAff -i $dtiToStructAff
Are there any examples on how to do this using AntsPy?
Describe the bug
I have a 3D image dtype='uint8' that I can plot like this:
ants.plot(img)
The image is segmented, so I can also plot different areas in isolation like this:
ants.plot(img==3)
But when I try to overlay the images in a plot, I get:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-38-2d83e2fbdb38> in <module>
----> 1 ants.plot(img1, img2)
/opt/conda/lib/python3.7/site-packages/ants/viz/plot.py in plot(image, overlay, blend, alpha, cmap, overlay_cmap, overlay_alpha, cbar, cbar_length, cbar_dx, cbar_vertical, axis, nslices, slices, ncol, slice_buffer, black_bg, bg_thresh_quant, bg_val_quant, domain_image_map, crop, scale, reverse, title, title_fontsize, title_dx, title_dy, filename, dpi, figsize, reorient)
1736 overlay = overlay.reorient_image2('LAI')
1737 ov_arr = overlay.numpy()
-> 1738 ov_arr[np.abs(ov_arr) == 0] = np.nan
1739 ov_arr = np.rollaxis(ov_arr, axis)
1740
ValueError: cannot convert float NaN to integer
To Reproduce
np1 = np.ones((3,3,3)).astype('uint8')
np2 = 2 * np1
img1 = ants.from_numpy(np1)
img2 = ants.from_numpy(np2)
ants.plot(img1, img2)
Desktop (please complete the following information):
works:
import ants
fi = ants.image_read(ants.get_ants_data('r16'))
mi = ants.image_read(ants.get_ants_data('r64'))
mytx = ants.registration(fi, mi, type_of_transform='SyN')
hangs:
import ants
fi = ants.image_read(ants.get_ants_data('r16'))
mi = ants.image_read(ants.get_ants_data('r64'))
fi = ants.resample_image(fi, (60,60), 1, 0)
mi = ants.resample_image(mi, (60,60), 1, 0)
mytx = ants.registration(fixed=fi, moving=mi, type_of_transform = 'SyN' )
Might have to do with cloning in the resampling.. because doing the resampling in ANTsR, saving the resampled images, loading them in ANTsPy, then running registration works as expected.
Should implement C++ antsImageClone to see if this fixes issue.
Hi,
I really appreciate for antspy library.
I want to use it for my python 3.7 codes.
Is there any support for python 3.7??
Thanks
Still experiencing the same issue reported in #26 on Mac OSX. This includes pip
installing using the new wheel: antspy-0.1.5-cp36-cp36m-macosx_10_7_x86_64.whl
or the pip install
command listed on the README.
It still looks like the installation doesn't do the ITK/VTK checks and installs that are in the setup.py
file. I've tried manually executing the bash scripts that are called in setup.py
and set the environment variables, etc, but still get the same error.
However, installing in linux (specifically Ubuntu 16.04 in a Docker container) using the README pip install
command works just fine.
Registration of diffusion HARDI ODFs
Registration of fiber orientation distribution functions (ODF) maps, using some rotation invariant features of the ODFs represented on a spherical harmonics basis.
Solution
In the literature, it is well known that, unlike scalar images, deforming ODF maps requires ODF reorientation to maintain its consistency with the local fiber orientations. This is done in some cases by applying the rotation matrix of the Jacobian of the transform directly to the SH coefficients to preserve its shape, at every iteration.
Alternative solution
Reorientation can also be done after the final iteration of the registration but better results are obtained when done at every iteration.
Questions
I recently started using ANTsPy and played with "antsRegistration". I would like to ask if antsRegistration's output files 'fwdtransforms' and 'invtransforms' contain the transformations/inv from each iteration or just the transformations/inv from the final iteration. What about "create_jacobian_determinant_image" ? It seems like it tells only about the last iteration, doesn't it ? Which function computes the Jacobian itself ?
Thanks
background:
followed python3.6 installation from here
created a virtual environment.
cloned ANTsPy
then called
sudo python3.6 setup.py develop --vtk
result is successful.
to use the toolkit, i then need:
pip3.6 install numpy
pip3.6 install pandas
pip3.6 install pillow
pip3.6 install sklearn
pip3.6 install scikit-image
pip3.6 install webcolors
pip3.6 install plotly
pip3.6 install matplotlib
sudo yum --enablerepo=ius-archive install python36u-tkinter
after this, i am successful at running the examples in:
help( ants.vol )
help( ants.sparse_decom2 )
following the nice developments of pathlib in python, maybe it would be nice to allow for PosixPath in all read functions
I see mask = ants.get_mask(data)
returns a binary mask in 'float32'. I also see that mask.astype(bool)
fails because Datatype <class 'bool'> is not supported. Is this a hard ANTs restriction or something that could be easily changed internally?
I ask so because not all nilearn functions (and other software as well) play well with floating point masks. It'd be convenient if masks could be saved as bool, or at least integer type.
I guess uint8 is not so bad as a workaround but it's an extra 7 bits of useless padding.
on Linux 3.10.0-514.10.2.el7.x86_64 #1 SMP Fri Mar 3 00:04:05 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
with Python 2.7.5
>>> import ants
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib64/python2.7/site-packages/ants/__init__.py", line 7, in <module>
from .core import *
File "/usr/lib64/python2.7/site-packages/ants/core/__init__.py", line 2, in <module>
from .ants_image import *
File "/usr/lib64/python2.7/site-packages/ants/core/ants_image.py", line 603
def image_physical_space_consistency(*images, tolerance=1e-2, datatype=False):
^
SyntaxError: invalid syntax
Hi
I like the idea of using ANTs from Python, i.e. power of Python/numpy with ANTs algorithms. But most of my development is on Windows (Visual Studio 2015).
What things would I need to modify to get this to work also on Windows?
it looks like pybind11 is supported for VS 2015 up.
ants (proper) builds on Windows, as does ITK/VTK (of course)...
thanks for any guidance.
bryn
Hi All,
I had some emails back and forth with Brian and he was able to help me solve this issue. Just wanted to post it here in case it can help someone else.
The current pre-compiled binaries lacked some functions I wanted, so I needed to build from the github master branch. My problem was when running "python setup.py install" the setup tried to put files at the root of the computing cluster which was read-only - I needed to install it in my user folder. It turns out you can change where this installation takes place (see these two links):
https://docs.python.org/2.5/inst/search-path.html
Hope this can help someone else!
Cheers,
Luke
Using os x 10.13.2.
After doing
pip install https://github.com/ANTsX/ANTsPy/releases/download/Weekly/antspy-0.1.4-cp36-cp36m-macosx_10_7_x86_64.whl
I get the error below when trying to import ants.
There is indeed no libvtkRenderingOpenGL2-8.1.1.dylib on my machine.
I would be grateful for any pointers on how to solve this?
ImportError Traceback (most recent call last)
in ()
----> 1 import ants
/anaconda3/lib/python3.6/site-packages/ants/init.py in ()
5 pass
6
----> 7 from .core import *
8 from .utils import *
9 from .segmentation import *
/anaconda3/lib/python3.6/site-packages/ants/core/init.py in ()
1
----> 2 from .ants_image import *
3 from .ants_image_io import *
4
5 from .ants_transform import *
/anaconda3/lib/python3.6/site-packages/ants/core/ants_image.py in ()
25 import inspect
26
---> 27 from .. import utils, registration, segmentation, viz
28 from . import ants_image_io as iio2
29
/anaconda3/lib/python3.6/site-packages/ants/utils/init.py in ()
1
----> 2 from .bias_correction import *
3 from .channels import *
4 from .convert_nibabel import *
5 from .crop_image import *
/anaconda3/lib/python3.6/site-packages/ants/utils/bias_correction.py in ()
7
8
----> 9 from . import process_args as pargs
10 from .get_mask import get_mask
11 from .iMath import iMath
/anaconda3/lib/python3.6/site-packages/ants/utils/process_args.py in ()
11
12 from ..core import ants_image as iio
---> 13 from .. import lib
14
15 _short_ptype_map = {'unsigned char' : 'UC',
/anaconda3/lib/python3.6/site-packages/ants/lib/init.py in ()
2
3 ## LOCAL ##
----> 4 from .antiAlias import *
5 from .antsImage import *
6 from .antsImageClone import *
ImportError: dlopen(/anaconda3/lib/python3.6/site-packages/ants/lib/antiAlias.cpython-36m-darwin.so, 2): Library not loaded: libvtkRenderingOpenGL2-8.1.1.dylib
Referenced from: /anaconda3/lib/python3.6/site-packages/ants/lib/antiAlias.cpython-36m-darwin.so
Reason: image not found
Hello,
I am getting a Segfault error while trying to register an 4D volume to a 3D volume.
tx_func2t1 = ants.registration(fixed=fixed, moving=moving, type_of_transform='Rigid')
I get this error but I'm not sure what is going on here:
Fatal Python error: Segmentation fault
Current thread 0x00007fea0e272740 (most recent call first):
File "/home/vasco/.local/lib/python3.6/site-packages/ants/registration/interface.py", line 651 in registration
File "resting_pipeline_ants.py", line 711 in step4
File "resting_pipeline_ants.py", line 126 in init
File "resting_pipeline_ants.py", line 1385 in
Any clues? Thanks in advance.
While using transforms on the MNI152 template I noticed that the output of to_nibabel() was flipped along the vertical plane. While investigating the issue, I noticed, that this is caused by a wrong extraction of the q-form parameters (direction, origin) from ITK.
ants_mni = ants.image_read('./MNI152.nii.gz')
nii_mni = nib.load('./MNI152.nii.gz')
ants_mni = ants_mni.to_nibabel()
print(ants_mni.get_qform())
print(nii_mni.get_qform())
results in:
[[ 2. 0. 0. -90.]
[ 0. -2. 0. 126.]
[ 0. 0. 2. -72.]
[ 0. 0. 0. 1.]]
[[ -2. 0. 0. 90.]
[ 0. 2. 0. -126.]
[ 0. 0. 2. -72.]
[ 0. 0. 0. 1.]]
Using the ITK internal functions for exporting to nifti file format, everything works as expected:
ants_mni = ants.image_read('./MNI152.nii.gz')
ants.image_write(ants_mni, './ANTS_MNI152.nii.gz')
ants_nii = nib.load('./ANTS_MNI152.nii.gz')
nii_mni = nib.load('./MNI152.nii.gz')
print(ants_nii.get_qform())
print(nii_mni.get_qform())
[[ -2. 0. 0. 90.]
[ 0. 2. 0. -126.]
[ 0. 0. 2. -72.]
[ 0. 0. 0. 1.]]
[[ -2. 0. 0. 90.]
[ 0. 2. 0. -126.]
[ 0. 0. 2. -72.]
[ 0. 0. 0. 1.]]
Although this could be used a a quick work around, like in the from_nibabel() implementation, a Nifti/Nibabel class export, should no rely on using hard-drive exports, when all the necessary information could be retrieved while loading the file initially.
Dear all,
Every time I run a registration routine, the deformations are automatically stored in a path like this: '/var/folders/sl/4rkybxmd5gn8d07qlxznhyg00000gp/T/tmpx0nsojq_0GenericAffine.mat'
Is it possible to change this?
I would like to store them in the pwd.
Installation does not work on Ubuntu 18.04, Python 3.7.4 (installed with miniconda), cmake 3.14.0, pybind11 2.2.4
I've tried the following command line:
pip install git+https://github.com/ANTsX/ANTsPy.git
Everything is fine until :
HEAD is now at 680942c1 BUG: antsApplyTransforms -e 4 would write input image rather than deformed image
Configuring ANTsPy library
-- The C compiler identification is GNU 7.4.0
-- The CXX compiler identification is GNU 7.4.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found PythonInterp: /home/rousseau/miniconda3/bin/python (found version "3.7.4")
CMake Error at pybind11/tools/FindPythonLibsNew.cmake:122 (message):
Python config failure: Python is 0-bit, chosen compiler is 64-bit
Call Stack (most recent call first):
pybind11/tools/pybind11Tools.cmake:16 (find_package)
pybind11/CMakeLists.txt:28 (include)
It seems that cmake does not find suitable Python version through pybind11.
Any help for appropriate configuration of cmake / pybind?
Thank you.
tried to write header info "direction" to nifti file. exactly passed the required args but still got the errer:
> TypeError: set_direction(): incompatible function arguments. The following argument types are supported:
> 1. (self: ants.lib.antsImage.ANTsImageF3, arg0: array) -> None
>
> Invoked with: <ants.lib.antsImage.ANTsImageF3 object at 0x7ff0281a95e0>, [[1.0, -0.0, 0.0], [-0.0, -1.0, 0.0], [0.0, 0.0, 1.0]]
when typing:
a.set_direction(info['direction'])
while my a is an antsImage data and my info['direction'] printed as:
In [164]: print(info['direction'])
[[1.0, -0.0, 0.0], [-0.0, -1.0, 0.0], [0.0, 0.0, 1.0]]
Is this a bug of ants when dealing with nifti image?
Describe the bug
In ants.build_template
, the following line already specifies a type_of_transform
argument for ants.registration
, so if a user passes type_of_transform
to build_template
, python will complain that it got multiple values for the argument.
TypeError: registration() got multiple values for keyword argument 'type_of_transform'
I came across this issue by trying to replicate the following ANTsR tutorial in ANTsPy.
To Reproduce
Steps to reproduce the behavior:
import ants
data = ants.image_read(ants.get_data("mni"))
template = ants.build_template(data, [data, data], type_of_transform="SyN")
Expected behavior
User can override the default transform. I'll open a PR.
Hi, I recently install ANTsPy via
pip install https://github.com/ANTsX/ANTsPy/releases/download/v0.1.4/antspy-0.1.4-cp36-cp36m-linux_x86_64.whl
when I try to convert numpy array to ants image by ants.from_numpy()
I get the following error message:
/lib/python3.6/site-packages/ants/core/ants_image_io.py in _from_numpy(data, origin, spacing, direction, has_components)
125 if not has_components:
126 itk_image = libfn(data, data.shape[::-1])
--> 127 ants_image = iio.ANTsImage(pixeltype=ptype, dimension=ndim, components=1, pointer=itk_image,
128 origin=origin, spacing=spacing, direction=direction)
129 ants_image._ndarr = data
AttributeError: module 'ants.core.ants_image' has no attribute 'ANTsImage'
I check the aforementioned ants_image_io.py and there is no attribute called 'ANTsImage'. It seems to be a bug.
Does anyone know how to fix that? Thanks a lot.
I did not know where to post this question, so I am dropping it here.
Describe the bug
I believe this may be related to #52. I've just built AntsPy from master, though, so the fix for #52 doesn't solve the issue.
For an ANTsImage (RSA), converting to and from nibabel changes their orientation (or at least their display). Also values for spacing and direction change.
To Reproduce
Steps to reproduce the behavior:
import ants
data = ants.image_read("some_nifti_rsa.nii")
ants.plot_ortho(data, flat=True)
ants.plot_ortho(ants.from_nibabel(ants.to_nibabel(data)), flat=True)
Expected behavior
The to_nibabel and from_nibabel conversions cancel each other out?
Screenshots
Desktop (please complete the following information):
The output "fwdtransforms" and "invtransforms" from ants.registration do not appear to be in a consistent order. I took a screenshot of two registration results—run with the same registration settings (SyNCC, in this case but I also observed this behavior with SyN and SyNRA)—where the order is reversed in the "fwdtransforms" and "invtransforms" across the two results:
This issue arose when I used the ants.apply_transforms function which resulted in a poor registration, but was fixed when I manually ordered the transforms. This issue also arises when I do not set the "outprefix."
Note that the "warpedmovout" and "warpedfixout" appear to be correctly registered.
For more context, I built from source and am using the latest edition (0.1.5).
hello,I find something strage when use image_read and image_write:
my code is that:
import SimpleITK as sitk import numpy as np import os import ants
file_3 = './input/wpre_3d.nii' data_3 = sitk.ReadImage(file_3)
the size of the wpre_3d.nii is 12M,the pix type read by sitk is :
data_3.GetPixelIDTypeAsString()
'16-bit unsigned integer'
the use the ant to read :
data_ant = ants.image_read(file_3) data_ant
pix type is float 32?
the write image :
ants.image_write(data_ant,'data_ant.nii')
size is the 24M。
how did it from 12M TO 24M?
thx!!
From the module in ants.contrib.sampling.affine3d
, the classes allow for X and y in the transform method, however when supplying X and y, only X transformed is returned (instead of the transformed tuple of X and y).
For example, in the case of the Shear3d
class, this could be fixed by adding the following logic at the end of the transform method:
else:
if y is None:
return self.tx.apply_to_image(X, reference=self.reference)
else:
return self.tx.apply_to_image(X, reference=self.reference), self.tx.apply_to_image(y, reference=self.reference)
Describe the bug
I am facing some difficulty with compiling the
To Reproduce
Steps to reproduce the behavior:
pip install cmake
pip install git+https://github.com/ANTsX/ANTsPy.git
python3 BIRL/results/BmANTsPy/run_ANTsPy.py BIRL/data_images/rat-kidney_/scale-5pc/Rat_Kidney_HE.jpg BIRL/data_images/rat-kidney_/scale-5pc/Rat_Kidney_PanCytokeratin.jpg BIRL/data_images/rat-kidney_/scale-5pc/Rat_Kidney_PanCytokeratin.csv BIRL/results/BmANTsPy/0
Traceback (most recent call last):
File "/home.dokt/borovji3/Medical-temp/experiments_anhir/BmANTsPy_20190325-153014/run_ANTsPy.py", line 18, in <module>
import ants
File "~/vEnv3/lib/python3.5/site-packages/ants/__init__.py", line 7, in <module>
from .core import *
File "~/vEnv3/lib/python3.5/site-packages/ants/core/__init__.py", line 2, in <module>
from .ants_image import *
File "~/vEnv3/lib/python3.5/site-packages/ants/core/ants_image.py", line 27, in <module>
from .. import utils, registration, segmentation, viz
File "~/vEnv3/lib/python3.5/site-packages/ants/utils/__init__.py", line 2, in <module>
from .bias_correction import *
File "~/vEnv3/lib/python3.5/site-packages/ants/utils/bias_correction.py", line 9, in <module>
from . import process_args as pargs
File "~/vEnv3/lib/python3.5/site-packages/ants/utils/process_args.py", line 13, in <module>
from .. import lib
File "~/vEnv3/lib/python3.5/site-packages/ants/lib/__init__.py", line 35, in <module>
from .antsRegistration import *
ImportError: ~/vEnv3/lib/python3.5/site-packages/ants/lib/antsRegistration.cpython-35m-x86_64-linux-gnu.so: undefined symbol: _Z14ANTSFileExistsRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Desktop (please complete the following information):
(sysname='Linux', nodename='cmpgrid-73', release='4.9.0-6-amd64', version='#1 SMP Debian 4.9.82-1+deb9u3 (2018-03-02)', machine='x86_64')
Python 3.5.3 (default, Jan 19 2017, 14:11:04) ; [GCC 6.3.0 20170118] on linux
any chance somebody has used ants.apply_transforms with trk files?
many thanks!
Alex
Is your feature request related to a problem? Please describe.
Currently, ants.motion_correction
outputs motion_parameters
as a list of MAT files that are saved to a temporary folder. This makes it so that if the user wants to save these transformations (to my understanding), he has to move these outputs somewhere else, manually, and write a mapping.txt file that specifies which file belongs to each volume, given that names are random.
It's also cumbersome to extract common motion parameter regressors from these MAT files from within python. My knowledge is that this requires calling in scipy or hdf5 to load the MAT files, extracting the affine from the dict, parsing it and storing the translation and rotation parameters manually. This also means that the end user has to know what the ANTs internal representation of an affine transformation looks like, which is well documented, but outside of ANTsPy.
Describe the solution you'd like
have the user be able to specify where to save the transformation matrices, and have their filenames sorted by index. This would ease storing files and allow easy identification of which affine belongs to which volume. If the folder already contains files with the same name, either throw an error before starting the motion correction, have a parameter to toggle overwrite (could default to True I guess), or add a suffix (the FSL solution).
output an extra motion_parameter_estimates
np.array or dictionary containing translation and rotation estimates for better interop with other software packages.
Describe alternatives you've considered
Open to suggestions.
Describe the bug
Error on install ants on linux 16.04
To Reproduce
I try to install ants from source , I run the command python setup.py develop under the directory,but it callback :
CMake Error at pybind11/tools/pybind11Tools.cmake:132 (add_library):
Cannot find source file:
antscore/antsApplyTransformsToPoints.cxx
I find the directory ANTsPy/ants/lib/antscore is empty , how can I fixed it ? or find the all files I need?
Expected behavior
I hope to install antspy easily ,thank you
Screenshots
If applicable, add screenshots to help explain your problem.
Just updated the repo and re-install the ANTsPy
git pull
python3 setup.py install
and when importing ants, I get the following error. The import ants
command worked fine a week ago.
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-9-78f96f50f910> in <module>()
----> 1 import ants
/usr/local/lib/python3.5/dist-packages/ants-0.1.2-py3.5-linux-x86_64.egg/ants/__init__.py in <module>()
9 ## IMPORT PYTHON MODULES
10
---> 11 from .core import *
12 from .utils import *
13
/usr/local/lib/python3.5/dist-packages/ants-0.1.2-py3.5-linux-x86_64.egg/ants/core/__init__.py in <module>()
1
----> 2 from .ants_image import *
3 from .ants_image_io import *
4
5 from .ants_transform import *
/usr/local/lib/python3.5/dist-packages/ants-0.1.2-py3.5-linux-x86_64.egg/ants/core/ants_image.py in <module>()
18 import inspect
19
---> 20 from .. import lib
21 from .. import utils, registration, segmentation, viz
22 from . import ants_image_io as iio2
/usr/local/lib/python3.5/dist-packages/ants-0.1.2-py3.5-linux-x86_64.egg/ants/lib/__init__.py in <module>()
6 ## CORE ##
7 from .antsImage import *
----> 8 from .antsImageClone import *
9 from .antsImageHeaderInfo import *
10 from .antsImageToImageMetric import *
ImportError: No module named 'ants.lib.antsImageClone'
Hi, sorry for opening yet another issue but I have a use problem that I don't know how to debug.
I'm trying to find a 3D registration that best match each sample of a source 4D image to the corresponding samples in a target 4D image.
My code is the following:
fixed = image_read("path_to_target_4D_image.nii.gz")
moving = image_read("path_to_source_4D_image.nii.gz")
mask = image_read("path_to_common_3D_mask.nii.gz")
reg = registration(fixed=fixed, moving=moving,
type_of_transform='SyNOnly', mask=mask, grad_step=0.5, flow_sigma=0, total_sigma=0, reg_iterations=(100, 40, 20), syn_metric='CC', syn_sampling=4, verbose=True)
print(reg)
This code runs, but doesn't try and calculate a registration. The print returns :
'warpedmovout' .... (same as moving)
'warpedfixout' ... (same as fixed)
'fwdtransforms' : []
'invtransforms' : []}
I had the same problem between 3D images when using 'Mattes' metric, that disappeared when using 'CC' instead but here no change of parameter seem to make the trick and I don't find any logs to understand why the registration is not calculated.
Thanks a lot,
points of failure
cd ANTsPy-master
should be
cd ANTsPy
itk clone/compile works until
[100%] Built target MGHIO-all
Install the project...
-- Install configuration: "Release"
CMake Error at cmake_install.cmake:31 (file):
file cannot create directory: /libs/lib/cmake/ITK-4.12. Maybe need
administrative privileges.
make: *** [install] Error 1
ITK_DIR: /Users/bavants/code/ANTsPy/itkbuild
Traceback (most recent call last):
File "setup.py", line 81, in <module>
subprocess.check_call(['./configure_antspy.sh'], cwd=setup_py_dir)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/subprocess.py", line 579, in check_call
retcode = call(*popenargs, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/subprocess.py", line 560, in call
with Popen(*popenargs, **kwargs) as p:
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/subprocess.py", line 950, in __init__
restore_signals, start_new_session)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/subprocess.py", line 1540, in _execute_child
raise child_exception_type(errno_num, err_msg)
PermissionError: [Errno 13] Permission denied
which is related primarily to the line
file cannot create directory: /libs/lib/cmake/ITK-4.12. Maybe need
which suggests a need to define a local install directory, perhaps within ANTsPy.
also need to document how to install ITK in the environment such that ANTsPy can see it.
Describe the bug
using the code provided for registration (in the tutorial area) results in a crash
fixed.plot(overlay=moving, title='Before Registration')
TypeError: plot() got an unexpected keyword argument 'overlay'
To Reproduce
run this code
fixed = ants.from_numpy(np.load(fixed_path)["arr_0"]).resample_image((64,64,64),1,0)
moving = ants.from_numpy(np.load(moving_path)["arr_0"]).resample_image((64,64,64),1,0)
fixed.plot(overlay=moving, title='Before Registration')
where the fixed path and moving path are npz files of a volume.
Expected behavior
I believe that plotly.plotly is deprecated and replaced by chart_studio.plotly
Desktop (please complete the following information):
Installation faliure while running sudo python setup.py install
Hi,
my installation has failed at 9% while "Scanning dependencies of target rgbToVector"
The full output is attached.
Do you have any idea of what might be happening?
Thanks,
Marco
Configuring ANTs core
fatal: destination path 'pybind11' already exists and is not an empty directory.
Configuring ANTsPy library
-- The C compiler identification is GNU 5.4.0
-- The CXX compiler identification is GNU 5.4.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found PythonInterp: /usr/bin/python (found version "2.7.12")
-- Found PythonLibs: /usr/lib/x86_64-linux-gnu/libpython2.7.so
-- Performing Test HAS_CPP14_FLAG
-- Performing Test HAS_CPP14_FLAG - Success
-- pybind11 v2.2.dev0
-- Performing Test HAS_FLTO
-- Performing Test HAS_FLTO - Success
-- LTO enabled
-- Configuring done
-- Generating done
-- Build files have been written to: /home/mpizzola/Installations/ANTsPy/build/temp.linux-x86_64-2.7
Scanning dependencies of target antsUtilities
Scanning dependencies of target antsImageAugment
[ 1%] Building CXX object CMakeFiles/antsImageAugment.dir/CONTRIB_antsImageAugment.cxx.o
[ 2%] Building CXX object CMakeFiles/antsUtilities.dir/antscore/antsUtilities.cxx.o
[ 3%] Building CXX object CMakeFiles/antsUtilities.dir/antscore/antsCommandLineOption.cxx.o
[ 4%] Building CXX object CMakeFiles/antsUtilities.dir/antscore/antsCommandLineParser.cxx.o
[ 5%] Building CXX object CMakeFiles/antsUtilities.dir/antscore/ReadWriteData.cxx.o
[ 5%] Building CXX object CMakeFiles/antsUtilities.dir/antscore/ANTsVersion.cxx.o
[ 6%] Linking CXX static library libantsUtilities.a
[ 6%] Built target antsUtilities
Scanning dependencies of target mergeChannels
[ 6%] Building CXX object CMakeFiles/mergeChannels.dir/LOCAL_mergeChannels.cxx.o
[ 7%] Linking CXX shared module /home/mpizzola/Installations/ANTsPy/ants/lib/antsImageAugment.so
[ 8%] Linking CXX shared module /home/mpizzola/Installations/ANTsPy/ants/lib/mergeChannels.so
[ 8%] Built target mergeChannels
Scanning dependencies of target rgbToVector
[ 9%] Building CXX object CMakeFiles/rgbToVector.dir/LOCAL_rgbToVector.cxx.o
In file included from /home/mpizzola/Installations/ANTsPy/ants/lib/pybind11/include/pybind11/pytypes.h:12:0,
from /home/mpizzola/Installations/ANTsPy/ants/lib/pybind11/include/pybind11/cast.h:13,
from /home/mpizzola/Installations/ANTsPy/ants/lib/pybind11/include/pybind11/attr.h:13,
from /home/mpizzola/Installations/ANTsPy/ants/lib/pybind11/include/pybind11/pybind11.h:43,
from /home/mpizzola/Installations/ANTsPy/ants/lib/LOCAL_rgbToVector.cxx:2:
/home/mpizzola/Installations/ANTsPy/ants/lib/LOCAL_rgbToVector.cxx: In function ‘PyObject* pybind11_init_wrapper()’:
/home/mpizzola/Installations/ANTsPy/ants/lib/pybind11/include/pybind11/common.h:194:15: error: redefinition of ‘PyObject* pybind11_init_wrapper()’
PyObject pybind11_init_wrapper()
^
/home/mpizzola/Installations/ANTsPy/ants/lib/pybind11/include/pybind11/common.h:272:5: note: in expansion of macro ‘PYBIND11_PLUGIN_IMPL’
PYBIND11_PLUGIN_IMPL(name) {
^
/home/mpizzola/Installations/ANTsPy/ants/lib/LOCAL_rgbToVector.cxx:116:1: note: in expansion of macro ‘PYBIND11_MODULE’
PYBIND11_MODULE(rgbToVector, m)
^
/home/mpizzola/Installations/ANTsPy/ants/lib/pybind11/include/pybind11/common.h:194:15: note: ‘PyObject pybind11_init_wrapper()’ previously defined here
PyObject *pybind11_init_wrapper()
^
/home/mpizzola/Installations/ANTsPy/ants/lib/pybind11/include/pybind11/common.h:272:5: note: in expansion of macro ‘PYBIND11_PLUGIN_IMPL’
PYBIND11_PLUGIN_IMPL(name) {
^
/home/mpizzola/Installations/ANTsPy/ants/lib/LOCAL_mergeChannels.cxx:189:1: note: in expansion of macro ‘PYBIND11_MODULE’
PYBIND11_MODULE(mergeChannels, m)
^
At global scope:
cc1plus: warning: unrecognized command line option ‘-Wno-inconsistent-missing-override’
CMakeFiles/rgbToVector.dir/build.make:62: recipe for target 'CMakeFiles/rgbToVector.dir/LOCAL_rgbToVector.cxx.o' failed
make[2]: *** [CMakeFiles/rgbToVector.dir/LOCAL_rgbToVector.cxx.o] Error 1
CMakeFiles/Makefile2:250: recipe for target 'CMakeFiles/rgbToVector.dir/all' failed
make[1]: *** [CMakeFiles/rgbToVector.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
[ 9%] Built target antsImageAugment
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2
Traceback (most recent call last):
File "setup.py", line 147, in
classifiers=['Programming Language :: Python :: 3.6'],
File "/usr/lib/python2.7/distutils/core.py", line 151, in setup
dist.run_commands()
File "/usr/lib/python2.7/distutils/dist.py", line 953, in run_commands
self.run_command(cmd)
File "/usr/lib/python2.7/distutils/dist.py", line 972, in run_command
cmd_obj.run()
File "setup.py", line 53, in run
self.run_command("build_py")
File "/usr/lib/python2.7/distutils/cmd.py", line 326, in run_command
self.distribution.run_command(command)
File "/usr/lib/python2.7/distutils/dist.py", line 972, in run_command
cmd_obj.run()
File "setup.py", line 38, in run
self.run_command("build_ext")
File "/usr/lib/python2.7/distutils/cmd.py", line 326, in run_command
self.distribution.run_command(command)
File "/usr/lib/python2.7/distutils/dist.py", line 972, in run_command
cmd_obj.run()
File "setup.py", line 100, in run
self.build_extension(ext)
File "setup.py", line 130, in build_extension
subprocess.check_call(['cmake', '--build', '.'] + build_args, cwd=self.build_temp)
File "/usr/lib/python2.7/subprocess.py", line 541, in check_call
raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['cmake', '--build', '.', '--config', 'Release', '--', '-j2']' returned non-zero exit status 2
CAN antspy use for CT abdomen registration??
I use antspy suyncc for CT abdomen registration, but ,It didn't work out so well Because of breathing, there's a big gap between the two 3d images
TODO: overlays, multislice, anatomical orientation ( via domainImageMap or whatever it's called ) + text annotation.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.