Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Registering Images to a Template - antsMultivariateTemplateConstruction2.sh #1760

Open
szan0808 opened this issue Jun 17, 2024 · 6 comments
Open

Comments

@szan0808
Copy link

Dear experts and developers,

I am dealing with a template that was generated with HCP subjects with the antsMultivariateTemplateConstruction2.sh script.
So, I started using those template images (T1w, T2w, FA, MD) as fixed images and correspondent subject's images as moving images for the antsRegistrationSyN.sh script. I felt like the results were sub-optimal and, surprisingly enough, I found out that the subject I was trying to register to the template belongs to the population that was used to construct the template. So, I compared the subject warped to template returned by antsMultivariateTemplateConstruction2.sh to the subject I registered to the template with antsRegistrationSyN.sh and they look significantly different.

After making sure that the preprocessing of the images used for the template construction and my subject were exactly the same, I made some attempts to hopefully improve the registration result:

  • I noticed the images returned by antsMultivariateTemplateConstruction2.sh are normalised by their mean, so I did the same for my subject
  • I tried enabling the histogram matching
  • I sharpened the template images prior to perform the antsRegistrationSyN.sh using a Laplace approach

Unfortunately I haven't had success, so far.

Is there anything I am missing? Next step for me would be to match the parameters set of the antsRegistration call made within antsMultivariateTemplateConstruction2.sh, but I feel like I am maybe missing some other fundamental steps.

The aim of all this is to replicate the registration made within antsMultivariateTemplateConstruction2.sh and use the same approach to register any subject to a template. Could I get some information on how the template/subject registration is performed within antsMultivariateTemplateConstruction2.sh?

Thanks,
Simone

@gdevenyi
Copy link
Contributor

Can you provide a complete collection of commands you have used, and examples of the inputs, outputs and clearly indicate what you thing is insufficient about the results.

@cookpa
Copy link
Member

cookpa commented Jun 17, 2024

antsMultivariateTemplateConstruction2.sh will write scripts called job_X_X.sh that contain the exact call to antsRegistration.

@szan0808
Copy link
Author

szan0808 commented Jun 18, 2024

Can you provide a complete collection of commands you have used, and examples of the inputs, outputs and clearly indicate what you thing is insufficient about the results.

Sure. I'll just show T1w images, but the template was construced using T1w, T2w, FA and MD.

  1. This is the T1w template:
    screenshot0001

  2. This is the sharpened T1w I produced using this filter hoping to improve the performance (I did the same for T2w, FA and MD):
    screenshot0002

  3. This is the subject's T1w warped to template as retured by antsMultivariateTemplateConstruction2.sh:
    screenshot0003

  4. This is the subject's T1w warped to template using the unmodified template images and this command:
    antsRegistrationSyN.sh -d 3 -o $pjdir/$line/T1w/${line}_T1w_brain_reg \ -f ${template_directory}/T1w.nii.gz -m $sbjdir/T1w_brain.nii.gz \ -f ${template_directory}/T2w.nii.gz -m $sjdir/T2w_brain.nii.gz \ -f ${template_directory}/FA.nii.gz -m $sjdir/fa.nii.gz \ -f ${template_directory}/MD.nii.gz -m $sjdir/adc.nii.gz \
    screenshot0004

  5. This is the subject's T1w warped to template using the unmodified template images and the command saved in the job_X_X.sh script, as suggested by @cookpa in his comment:
    screenshot0005
    Here I would have expected to get the same as 3), and that is pretty much the point I am trying to discuss here. Is there something else going on in antsMultivariateTemplateConstruction2.sh before the command stored in job_X_X.sh is executed (here is why I later attempted the sharpening)?

  6. This is the subject's T1w warped to template using the sharpened template images and using a command like the one used in 4):
    screenshot0006

The other attempts using normalised subject's images didn't help with matching 3) either.

To answer you, @gdevenyi , there is a noticeable difference in the cortical areas and that's where my attention will go for the next steps of my processing. The warped images retured by antsMultivariateTemplateConstruction2.sh seem the most accurate and I would like to replicate that before extending the processing to subjects outside the population used to construct the template.

Thanks again,
Simone

@cookpa
Copy link
Member

cookpa commented Jun 18, 2024

The only pre-processing that should happen in the template script is N4BiasFieldCorrection, which is done if the -n argument is 0 or unspecified. If N4 is run, it should appear in your job*.sh files.

It's hard to gauge from screen caps how different the results are. There will be some run-to-run variability because of random sampling in the affine stage. Also, your output from the template script is registered to the previous template - after each set of pairwise registrations, the template is updated. After the last run, the final template is generated, so the registrations are out of date. However, you can find template (n - 1) under the intermediateTemplates/ directory. Registering the template input images (using the command precisely as written in job.sh) will be the closest you can get to doing the same thing.

Sharpening is done on the template, not the individual images, so that's not it. Dividing the images by their mean is done during averaging after registration.

@gdevenyi
Copy link
Contributor

Also, your output from the template script is registered to the previous template - after each set of pairwise registrations, the template is updated. After the last run, the final template is generated, so the registrations are out of date. However, you can find template (n - 1) under the intermediateTemplates/ directory.

I think this is where the unexpected difference arises.

@szan0808
Copy link
Author

szan0808 commented Jun 18, 2024

The only pre-processing that should happen in the template script is N4BiasFieldCorrection, which is done if the -n argument is 0 or unspecified. If N4 is run, it should appear in your job*.sh files.

I noticed that, as the images were labelled as "Repaired", but the dataset I'm using is already preprocessed, so I left it out for now. I might include it, just in case.

Also, your output from the template script is registered to the previous template - after each set of pairwise registrations, the template is updated. After the last run, the final template is generated, so the registrations are out of date. However, you can find template (n - 1) under the intermediateTemplates/ directory. Registering the template input images (using the command precisely as written in job.sh) will be the closest you can get to doing the same thing.

As @gdevenyi pointed out, sounds like this could be the clarification I was after. I'll just run a quick test using the (n-1) template. That would not be relevant when working with subjects outside the template population, but it will be hopefully a good way to confirm that this is what causes these differences.

Sharpening is done on the template, not the individual images, so that's not it. Dividing the images by their mean is done during averaging after registration.

I confirm I only sharpened the template's images (T1w, T2w, FA, MD). That step makes sense to me, although it didn't have much effect on the final result, as the template images would generally be smoother that the subjects'.

Thanks you both for clarifying. I'll run some more tests and I'll report here the results.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants