ANTsX / ANTsPy

A fast medical imaging analysis library in Python with algorithms for registration, segmentation, and more.
https://antspyx.readthedocs.io
Apache License 2.0
632 stars 161 forks source link

antspy is much slower than ANTs. #717

Open hz1z opened 3 days ago

hz1z commented 3 days ago

For the same functionality, I can get results in one minute using the ANTs command line, but it’s very slow and doesn’t produce results when using Python. image

python

import ants

fix_img_pt = '/home/hyh/code/coregister/tmax.nii.gz'
move_img_pt = '/home/hyh/code/coregister/dwi_dcm.nii.gz'
save_path = './reg_img.nii.gz'

fix_img = ants.image_read(fix_img_pt)
move_img = ants.image_read(move_img_pt)

outs = ants.registration(fix_img, move_img, type_of_transforme='Affine')

reg_img = outs['warpedmovout']
ants.image_write(reg_img, save_path)

ANTs

antsRegistrationSyN.sh -d 3 -f tmax,nii.gz -m dwi_dcm.nii.gz -o aff -t a
ntustison commented 3 days ago

Even though they're both affine registrations, the parameters between the two are different.

cookpa commented 3 days ago

There were some speed differences fixed in #703, but as @ntustison says, parameters differ. To compare like to like, you need to use type_of_transform='antsRegistrationSyN[a]'

hz1z commented 3 days ago
outs = ants.registration(fix_img, move_img,
                             type_of_transforme='Affine', verbose=True)

try to use verbose to debug, i find ... image I think it didn’t perform the registration; it just got stuck at…

hz1z commented 3 days ago

It’s possible that I want to register DWI to the three-component Tmax, and I tried with one component T1 and DWI, and there was no issue; it worked.

ntustison commented 3 days ago

Note that there is overlap when you use the family of transforms, e.g., type_of_transforme="antsRegistrationSyN[a]". Consult the help menu for further guidance.

cookpa commented 3 days ago

It’s possible that I want to register DWI to the three-component Tmax, and I tried with one component T1 and DWI, and there was no issue; it worked.

That's probably the problem then, antspy sees the 4D image and tries to do a 4D registration (much slower).

In your command line example you had -d 3. You must extract a 3D image to use here (eg, b0 from dwi) or the output will be incorrect

cookpa commented 3 days ago

https://github.com/ANTsX/ANTs/wiki/Dimensionality-or-ImageDimension-option-in-ANTs