ANTsX / ANTs

Advanced Normalization Tools (ANTs)
Apache License 2.0
1.15k stars 374 forks source link

Questions about buildtemplateparallel and antsMultivariateTemplateConstruction #806

Closed Pamsin closed 5 years ago

Pamsin commented 5 years ago

Dear ANTS experts,

I am reading the codes buildtemplateparallel and antsMultivariateTemplateConstruction.

What I cannot understand is why it used four times "${templatename}warp.nii.gz" when warping each template by the resulting transforms in the function "shapeupdatetotemplate ".

The code is "${ANTSPATH}/WarpImageMultiTransform ${dim} ${template} ${template} -i ${templatename}Affine${afftype} ${templatename}warp.nii.gz ${templatename}warp.nii.gz ${templatename}warp.nii.gz ${templatename}warp.nii.gz -R ${template}". (buildtemplateparallel: line 414; antsMultivariateTemplateConstruction: line 262)

According to me, to calculate the inverse transform, we just need to use the "-i Affine.mat InverseWarp.nii.gz". Is it right? Why did it use the "*warp.nii.gz" so many times here?

Could anyone explain it? Or recommend a reference for this algorithm?

Any suggestions would be much appreciated.

Thanks!

cookpa commented 5 years ago

The template update warp field is scaled by 0.25 (by default, the user can reduce it) and then applied four times, so the resulting warp vector at some point will have similar magnitude to the original version, but it will be slightly regularized because of linear interpolation at each of the four steps.

I can't recall the original reference for doing this in template construction, but I think it might have been one of the SPM papers.

ntustison commented 5 years ago

We're actually determining the transform which updates the template shape to shift it closer to the estimated true mean of the cohort. In order to minimize deviations from a diffeomorphic transform, an exponentiated approach is used whereby the average displacement field transform is first multiplied by the gradient step (< 1.0, default = 0.25) and composed with itself multiple times.

Pamsin commented 5 years ago

We're actually determining the transform which updates the template shape to shift it closer to the estimated true mean of the cohort. In order to minimize deviations from a diffeomorphic transform, an exponentiated approach is used whereby the average displacement field transform is first multiplied by the gradient step (< 1.0, default = 0.25) and composed with itself multiple times.

Thanks for the answer. So, I think this four times warp is because of using the gradien step 0.25 (1/4)? Should I need to change the warp times when I use a different gradient step? Another queston is why we use the file warp.nii.gz (from subject to template) to calculate the template shift? This algorithm just calculated "the inverse field by the resulting average affine transform". Why don't it use InverseWarp.nii.gz (from template to subject)?

Does it work if using "${ANTSPATH}/WarpImageMultiTransform ${dim} ${template} ${template} -i ${templatename}Affine${afftype} ${templatename}InverseWarp.nii.gz -R ${template}"."

ntustison commented 5 years ago

So, I think this four times warp is because of using the gradien step 0.25 (1/4)?

No, it's simply a coincidence.

Should I need to change the warp times when I use a different gradient step?

No.

Another queston is why we use the file warp.nii.gz (from subject to template) to calculate the template shift? This algorithm just calculated "the inverse field by the resulting average affine transform". Why don't it use InverseWarp.nii.gz (from template to subject)?

The "inverse transform" applied during the shape updated sense is not the same in the sense of the total transform found between template and subject. It's much more complicated than that which is why your proposed use of the inverse transform wouldn't work. I'd recommend reading the paper, specifically section 2.2.2.

Pamsin commented 5 years ago

So, I think this four times warp is because of using the gradien step 0.25 (1/4)?

No, it's simply a coincidence.

Should I need to change the warp times when I use a different gradient step?

No.

Another queston is why we use the file warp.nii.gz (from subject to template) to calculate the template shift? This algorithm just calculated "the inverse field by the resulting average affine transform". Why don't it use InverseWarp.nii.gz (from template to subject)?

The "inverse transform" applied during the shape updated sense is not the same in the sense of the total transform found between template and subject. It's much more complicated than that which is why your proposed use of the inverse transform wouldn't work. I'd recommend reading the paper, specifically section 2.2.2.

Hi Nick,

I have read the paper but I still cannot figure out why we use the warp.mii.gz to cal the template shift. However, it may not be important because I just need to use it.

There are three programmes "buildtemplateparallel, antsMultivariateTemplateConstruction and antsMultivariateTemplateConstruction". So the last question is what is the difference between them? Olny the TRANSFORMATIONTYPE? Which one I can choose to start with? All of them can reach the SyN.

Thanks a lot!

ntustison commented 5 years ago

buildtemplateparallel.sh was one of the initial scripts to do template building. It's functionality was extended in antsMultivariateTemplateConstruction.sh, including multimodal templates. antsMultivariateTemplateConstruction2.sh simply replaces the use of the original ANTS program with the more recent antsRegistration tool. We recommend using either one of the latter two scripts.

Pamsin commented 4 years ago

buildtemplateparallel.sh was one of the initial scripts to do template building. It's functionality was extended in antsMultivariateTemplateConstruction.sh, including multimodal templates. antsMultivariateTemplateConstruction2.sh simply replaces the use of the original ANTS program with the more recent antsRegistration tool. We recommend using either one of the latter two scripts.

Hi Nick,

Sorry to bother you again.

I am trying to use antsMultivariateTemplateConstruction2.sh to generate a template for my data. However, I cannot get a good a result. I mean that the image is very blurred in the border region where it couldn't distinguish the gray matter and the white matter. I put an image compared with the icbm template in the attached file.

Could you tell me where I can improve for the parameters of this program? Or other codes and methods I can try to get the template?

The code I used is as following: antsMultivariateTemplateConstruction2.sh \ -d 3 \ -o ${outputPath}/T_ \ -i 5 \ -g 0.25 \ -c 4 \ -f 8x4x2x1 \ -s 3x2x1x0 \ -q 100x70x50x10 \ -n 0 \ -r 1 \ -l 1 \ -m MI \ -t SyN \ ${inputPath}/*.nii.gz

ComparedWithICBM

Thanks a lot!

ntustison commented 4 years ago

Have you looked at these examples?

Pamsin commented 4 years ago

Have you looked at these examples?

Yes, but I just read the sh files to confirm the transformation and parameters. I don't know which parameters I can change to improve the border region.

ntustison commented 4 years ago

You should actually run them, especially BrainSlices, as they're relevant to your problem.