Comments (6)
here is an example, as you requested, as a jupyter notebook
https://github.com/ANTsX/ANTsPy/blob/master/tutorials/concatenateRegistrations.ipynb
from antspy.
from antspy.
Hi,
I'm having problem in replicating in ANTsPy the results obtained using WarpImageMultiTransforms. Given the same transformation (computed with ants as well) I obtain two very different output images.
ANTsPy Version: 0.2.6
ANTs Version: 2.3.4.dev187-gb37e8
Here the code I'm using:
fixed = ants.image_read(fixed_fn)
moving = ants.image_read(moving_fn)
warped = ants.apply_transforms(fixed=fixed,
moving=moving,
transformlist=[f'{tmp_dir}/tract2mni0GenericAffine.mat', f'{tmp_dir}/tract2mni1InverseWarp.nii.gz'],
whichtoinvert=[True, False]
)
ants.image_write(warped, f'{tmp_dir}/warped.nii.gz')
os.system(f'WarpImageMultiTransform 3 {moving_fn} {tmp_dir}/warped_cli.nii.gz -R {fixed_fn} -i {tmp_dir}/tract2mni0GenericAffine.mat {tmp_dir}/tract2mni1InverseWarp.nii.gz')
Then if I load and compare the two output images I obtain very different results:
warped_py = ants.image_read(f'{tmp_dir}/warped.nii.gz')
warped_cli = ants.image_read(f'{tmp_dir}/warped_cli.nii.gz')
np.array_equal(warped_py.view(), warped_cli.view())
>>> False
warped_py.view().mean()
>>> -0.3322511
warped_cli.view().mean()
>>> 27.890787
warped_py.view()[:2]
array([[[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.],
...,
[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.]],
[[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.],
...,
[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.]]], dtype=float32)
warped_cli.view()[:2]
>>> array([[[90., 90., 90., ..., 90., 90., 90.],
[90., 90., 90., ..., 90., 90., 90.],
[90., 90., 90., ..., 90., 90., 90.],
...,
[90., 90., 90., ..., 90., 90., 90.],
[90., 90., 90., ..., 90., 90., 90.],
[90., 90., 90., ..., 90., 90., 90.]],
[[90., 90., 90., ..., 90., 90., 90.],
[90., 90., 90., ..., 90., 90., 90.],
[90., 90., 90., ..., 90., 90., 90.],
...,
[90., 90., 90., ..., 90., 90., 90.],
[90., 90., 90., ..., 90., 90., 90.],
[90., 90., 90., ..., 90., 90., 90.]]], dtype=float32)
From the last print it seemed the difference could have been the default value =90. in one case versus =0. in the other case, but even after changing the defaultvalue=90.
in ants.apply_transforms
the two warped images result different.
from antspy.
Please repost as a new issue. Also, please compare with antsApplyTransforms
and not WarpImageMultiTransform
as the latter is quasi-deprecated.
from antspy.
I answer right here because I've found a solution for my use-case, which is a particular case. (after you read this answer let me know if you still prefer I move all this discussion to a new issue).
First of all, just as a sanity check, I did the comparison you requested and it was successful i.e., antsApplyTransforms
and ants.apply_transforms
returned the same results.
Then, to clarify my use-case, I did the comparison considering as moving image an "identity" warp created using mrtrix, which is not a standard scalar positive image since it contains both negative and positive values. The apply transformation step is part of the conversion of an ants warp to a warp compatible with mrtrix. Here's the official mrtrix guide of the conversion [https://community.mrtrix.org/t/registration-using-transformations-generated-from-other-packages/2259].
The aforementioned guide contains also the answer to my problem, because it states how to substitute WarpImageMultiTransforms
with antsApplyTransforms
in this use-case. The gist is that mrtrix requires a marker value different from plausible values (after warpImageMultiTransform was 90.), that they transforms to NaN in a step warpcorrect
that modifies the warp according to mrtrix requirements.
from antspy.
Yes, please post as a new issue. This issue is closed. If it's related, you can always provide a link back to this issue.
from antspy.
Related Issues (20)
- ants/lib.cpython-311-darwin.so not valid for use in process: library load disallowed by system policy HOT 1
- Error in outputting deformation field and Jacobian determinant HOT 4
- resample_image_to_target / images_to_matrix HOT 9
- How to output and save deformation fields HOT 6
- compose_ants_transforms change HOT 3
- broken b-spline fitting HOT 2
- B-spline curve fitting failures HOT 1
- Ubuntu Python 3.9 installation error (sha256 mismatch) HOT 3
- potential bug: reference leak when torch is loaded and a function errors HOT 1
- ants.iMath_histogram_equalization HOT 2
- 有没有GPU加速版本的..... HOT 1
- File errors in `ants` folder under home directory crashes ANTsPyx HOT 4
- Encountering the error "RuntimeError: Registration failed with error code 1", when MRA images and T1-weighted images are co-registered with "SyN" HOT 11
- ANTsPy crashes Python when registering two images HOT 4
- Circular import error HOT 2
- Support for HDF5/NWB HOT 1
- Difference between `ants.apply_transforms` and `transform.apply_to_image` with multiple transforms HOT 3
- An question about the return results of ants.registration HOT 6
- ants_transform.apply_to_image broken for displacement field transforms HOT 2
- 'ANTsImage' object has no attribute 'endswith' HOT 9
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from antspy.