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
628 stars 161 forks source link

finding some properties of antsRegistration in ants.registration #358

Open amirreza1998 opened 2 years ago

amirreza1998 commented 2 years ago

hi i have code below in ANTs to convert to ANTspy code :

f = <fixed image path>
m = <moving image path>

${ANTSPATH}/antsRegistration -d 3 \
            -r [$f, $m,1]\
            -m MI[$f,$m,1,32] \
                        -t affine[ 0.5 ]  \
            -c [50x50x5 , 1.e-7, 5]  \
                        -s 4x2x1  \
            -f 4x2x1 \
                        -m MI[$f,$m,1,32] \
                        -t syn[ 0.25 , 2, 2 ]\
                        -c [5x5x5,1.e-7,5]  \
                        -s 4x2x1  \
                        -f 4x2x1 \
                        -u 1 \
            -o [${nm},${nm}_diffToMRN1.nii,${nm}_invToMRN1.nii]

and i make below code in ANTspy :

MImetric = ["MattesMutualInformation", fname1, fname2, 1,  32]
metrics = list( )
metrics.append(MImetric)
mytx_affine = ants.registration(fixed=fname1, moving=fname2,
                          type_of_transform = 'Affine',
                          grad_step=0.5,                                               #           -t affine[ 0.5 ] set that 0.5 gradient step
                          multivariate_extras=metrics,                                 #          -m MI[$f,$m,1,32] \
                          aff_iterations=(50, 50, 5),                                  #       -c $its  \         =>              its=[50x50x5,1.e-7,5]
                          aff_smoothing_sigmas=(4, 2, 1),                              #        -s 4x2x1  \
                          aff_shrink_factors=(4, 2, 1),                                #        -f 4x2x1 \
)

mytx4 = ants.registration(fixed=fname1, moving=fname2,
                          type_of_transform = 'SyNOnly',
                          syn_sampling=32, 
                          reg_iterations=(5, 5, 5),                                  #       -c $its  \         =>              its=[50x50x5,1.e-7,5]
                          multivariate_extras=metrics,                                 #          -m MI[$f,$m,1,32] \

                          grad_step=0.25,                                             #tx=" syn[ 0.25 , 2, 2 ] "
                          flow_sigma=2,
                          total_sigma=2,

                          #aff_smoothing_sigmas=(4, 2, 1),                              #        -s 4x2x1  \
                          #aff_shrink_factors=(4, 2, 1),                                #           -f 4x2x1 \

                          initial_transform = mytx_affine['fwdtransforms'][0],
                          outprefix = "diffToMRN1_",                                    #          -o [${nm},${nm}_diffToMRN1.nii,${nm}_invToMRN1.nii]

)
mywarpedimage = ants.apply_transforms( fixed=fname1, moving=fname2,
                                           transformlist=mytx4['fwdtransforms'] )

but i don't know how should implement :

it's very important to me to convert this code i will be so thankful if you could help me

cookpa commented 2 years ago

I made a PR to show users what's being done (#377) but not all of the command line options are exposed in the function.

Some of the things you asked about are done by default, for example -r [ fixed, moving, 1 ] is the default initialization.

If you really need to reproduce your CLI command precisely, I think you should write a script to run it directly.