ANTsPy icon indicating copy to clipboard operation
ANTsPy copied to clipboard

Minimizing deformation when applying registration with two identical images

Open IlvaHou55 opened this issue 4 years ago • 8 comments

Hi everyone,

Two days ago I opened this issue on the global ANTs page. I encountered that with ants.registration(fixed=fixedmri, moving=fixedmri, type_of_transform='SyN') my original image and registered image were quite different, where you would expect no transformation because two identical images are used for the fixed and moving image.

Please see the thread for a reproducible example.

Now I wondered how I could reproduce the example of @cookpa in ANTsPy:

export ITK_GLOBAL_DEFAULT_NUMBER_OF_THREADS=1
antsRegistration -d 3 -u 0 -v 1 \
   -t SyN[0.1] \
   -m Mattes[ MRI_4.nii , MRI_4.nii , 1, 64, Regular ] \
   -c [ 25, 1e-8 ,10 ] -f 1 -s 0 \
   -o [ MRI_4ToSelf, MRI_4ToSelfDeformed.nii.gz ] 

I thought of: grad_step=0.1 because of -t SyN[0.1] aff_sampling=64 and syn_sampling=64 because of -m Mattes[ MRI_4.nii , MRI_4.nii , 1, 64, Regular ] reg_iterations=(25, 1e-8, 10) because of -c [ 25, 1e-8 ,10 ]

However, regarding the smoothing and downsampling, the ANTsPy docs state 'we will set the smoothing and multi-resolution parameters based on the length of this (reg_iterations) vector.' Does this mean I cannot manually set these parameters to zero-smoothing and zero-downsampling?

Thank you in advance.

IlvaHou55 avatar Nov 04 '21 08:11 IlvaHou55

I think you want reg_iterations=(X) for X iterations at full resolution. If you have reg_iterations = (X,Y,Z) it will do three levels: X downsampled 4x, Y downsampled 2x, and Z at full resolution. You may also want type_of_transform='SyNOnly' to disable affine registration.

I'm not sure how you set the other convergence parameters.

cookpa avatar Nov 04 '21 13:11 cookpa

MI is not the best choice for detecting images with zero difference. if you want to add such a check you might do:

if mean( imgF - imgM ) == 0 : return identity else : do registration

as others said, mutual information is a probabilistic measurement with built-in uncertainty. i would not worry about sub-voxel displacements coming out of it.

stnava avatar Nov 04 '21 15:11 stnava

also - I would recommend using ANTsPy I/O as follows:

import ants
img=ants.image_read("MRI_4.nii").iMath("Normalize")
img2=ants.image_read("MRI_4.nii").iMath("Normalize")
reg=ants.registration(img,img2,'SyN')
# check mag of def
warp=ants.image_read( reg['fwdtransforms'][0] ).split_channels()
for k in range(3):
     print(warp[k].abs().max())
# 0.115857765
# 0.25167125
# 0.15904859

voxel size is 1mm so these max displacements are far under that. you should read these as effectively zero.

stnava avatar Nov 04 '21 16:11 stnava

@cookpa Thank you for your reply. Why would you want to disable the affine transformation?

IlvaHou55 avatar Nov 04 '21 16:11 IlvaHou55

Just trying to isolate the variability in SyN.

cookpa avatar Nov 04 '21 16:11 cookpa

@cookpa I see, but for my application I need them both, so think it is fair if I use them both in this test case.

IlvaHou55 avatar Nov 04 '21 16:11 IlvaHou55

@stnava Thank you for your reply. Would you always normalize the images before registration?

IlvaHou55 avatar Nov 04 '21 16:11 IlvaHou55

if they have negative values, then yes

stnava avatar Nov 04 '21 16:11 stnava