Coder Social home page Coder Social logo

Comments (6)

stnava avatar stnava commented on August 15, 2024

here is an example, as you requested, as a jupyter notebook

https://github.com/ANTsX/ANTsPy/blob/master/tutorials/concatenateRegistrations.ipynb

from antspy.

dgutman avatar dgutman commented on August 15, 2024

from antspy.

pietroastolfi avatar pietroastolfi commented on August 15, 2024

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.

ntustison avatar ntustison commented on August 15, 2024

Please repost as a new issue. Also, please compare with antsApplyTransforms and not WarpImageMultiTransform as the latter is quasi-deprecated.

from antspy.

pietroastolfi avatar pietroastolfi commented on August 15, 2024

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.

ntustison avatar ntustison commented on August 15, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.