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

Template initialization to improve convergence #1227

Merged
merged 5 commits into from
Aug 24, 2021
Merged

Conversation

cookpa
Copy link
Member

@cookpa cookpa commented Aug 18, 2021

Fixes #1216. In addition to enforcing the use of AverageImages in population average templates, I made a few tweaks to help convergence:

  • Use @gdevenyi 's idea to do a COM alignment of each image to the initial average
  • Don't sharpen the population average, resulting in a smoother initial template
  • Also don't sharpen after the initial rigid alignment

After the population average + initial rigid stage, the statistic (mean, normalized mean, median) and sharpening options follow whatever the users specify on the command line.

In order to make the process more transparent to users, I added an output folder intermediateTemplates/, which contains each template and, if it exists, the template shape update. This will let users visually inspect their templates at every stage, and the update warps can be interrogated (eg, for magnitude or volume change) to assess convergence.

Currently, the only way to retain intermediate output is to back up everything, which can take up a lot of disk space.

Additionally, I made a few fixes to documentation and error checking, including:

  • Check number of shrink factor levels is equal to number of iteration levels (2.sh only)
  • Check the expected number of warped output images exist for each shape update. This prevents a quiet error when one or more registrations fail for whatever reason, and the template gets built from a subset of the input.

Back up templates and shape update warps, so that QC and convergence checking can be done without having to back up everything

Also various fixes to documentation and error checking
@cookpa cookpa changed the title Template converge Template initialization to improve convergence Aug 18, 2021
@hjmjohnson hjmjohnson self-requested a review August 18, 2021 14:16
Copy link
Collaborator

@hjmjohnson hjmjohnson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These look like good changes. Thank you for the style fixes cleaning of eol spaces.

The temporary directory will be great for debugging.

@gdevenyi
Copy link
Contributor

Looks great! My only suggestion is to perhaps improve the documentation a bit to clarify how the different modes work with this new COM modification.

@@ -837,13 +859,34 @@ for (( i = 0; i < $NUMBEROFMODALITIES; i++ ))
echo "--------------------------------------------------------------------------------------"
# Normalize but don't sharpen at this stage
${ANTSPATH}/AverageImages $DIM ${TEMPLATES[$i]} 2 ${CURRENTIMAGESET[@]}
# Quickly align COM of input images to average, and then recompute average
IMAGECOMSET=()
for (( j = 0; j < ${#CURRENTIMAGESET[@]}; j+=1 ))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One other implementation note here, I found for best performance I often had to do two rounds of this.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you have an example of this? I can't see how it would help except to shift the location of the image set inside the bounding box. Which may be desirable (or not if it shifts the wrong way)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After checking things over, my tests show I don't actually need two rounds, however, padding/recropping the template is important as otherwise you can get a non-centered FOV.

Compare, left no pad/recrop vs right:
https://imgur.com/a/ded9IPL

Pad/recrop code:
https://github.com/CoBrALab/optimized_antsMultivariateTemplateConstruction/blob/master/modelbuild.sh#L486-L490

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that's a good idea, but this whole PR started because a user wanted to control the size of their template image. Also, unless -y 0 is used, the template will re-center itself to minimize the average translation.

After the initial average which sets the template volume size, users
can now control mean / norm  mean / median.

Added a summarizeimageset function to antsMultivariateTemplateConstruction.sh,
which makes it easier and more consistent to update the template.

Added some additional checks to both scripts to ensure that the template actually
gets updated properly, using all the images it ought to have.
@cookpa
Copy link
Member Author

cookpa commented Aug 24, 2021

I'm going to merge this now. Thanks for the reviews and suggestions

@cookpa cookpa merged commit 5ffa75d into master Aug 24, 2021
@ntustison
Copy link
Member

Thanks for all this work, @cookpa and others @gdevenyi @hjmjohnson.

@cookpa cookpa deleted the templateConverge branch April 20, 2022 19:34
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

Successfully merging this pull request may close these issues.

Templates not sized according to the largest input image
4 participants