Skip to content

Best Templates for MAGeT

raihaan edited this page Nov 16, 2020 · 22 revisions

This is a set of steps for optimizing MAGeTbrain segmentations by choosing the best templates for a segmentation. This should only really be needed for populations where the subjects are a large distance from the atlases in terms of anatomy. This tutorial was made from pieces of emails and chats with Matt Park, Raihaan Patel and Gabriel Devenyi. -- Eduardo Garza-Villarreal

A summary of the steps required:

  1. Label ~100-200 possible template brains using the 1st stage in MAGeT brain (simplified or morpho branches). It will do 1_register & 2a_resample labels which are simply atlas-to-template registrations.
  2. Make QC images for each atlas to template combination, resulting in ~500 QC images, ~100 per atlas (if you have 100 template brains).
  3. Quality control the templates for each atlas registration.
  4. Choose the best atlas to template registrations, and use them as template brains.

Now here it is step by step:

Atlas-to-template registrations

Create a new directory wherever you want. Let's call it best_template

$ mkdir best_template

Create the MAGeT structure inside the folder input as if you were performing MAGeTbrain or MAGeTmorph. Populate the input/atlas folder as usual. Place 1 image in your input/subjects/brains, as opposed to your full dataset. In input/templates/brains, place the 100-200 candidate templates which you want to assess. The following steps will allow you to check the atlas-template registration for these files.

Run MAGeTbrain to only run the template stage:

$ mb run register

This should submit jobs to perform all atlas-template registrations.

This will create output/registrations folder, which will be populated with atlas-template transforms as your jobs run.

Warp the atlas labels to each template

Check inside output that you have the folder registrations with one folder per atlas (i.e. brain1) and inside one folder per template (brain1/subject1, brain1/subject2, etc.). Inside each template folder you will find several xfm and mnc files.

In this step, you want to use the xfm files to warp each atlas label to each template. You can do this using the generate-template-label-jobs.sh script inside your MAGeTbrain/bin folder. Make sure you are in your project directory (ie in the parent directory of input and output) and run as follows:

$ generate-template-label-jobs.sh > joblist

This will create a file joblist. Check it with nano and make sure it is a set of mincresample jobs on your data.

Run the jobs qbatch -c 100 -w 2:00:00 joblist

Vote the template labels

You will find the QC images in output/labels/brain1/template1/labels.mnc.

We can now vote them so we only have one label per template:

> cd output/labels
> mkdir voted
> for file in brain1/*; do echo $file; voxel_vote brain{1..5}/$(basename $file)/labels.mnc voted/$(basename $file)_labels.mnc; done 

Check the QC of the images

You will find the final QC labels in output/labels/voted/template_name_labels.mnc. Download them and check them using Display or Register. Compare the original subject brain with the resulting label.

Example:

Display -gray subjects/brains/subject1_t1.mnc -label output/labels/brain1_t1/template1/template1.mnc

Choose the best templates

Here is the tricky thing. The goal is to find images from your dataset that had good labels from each of the 5 brains, or as many as possible. The registrations are done only once so the quality will not be as good as the final segmentation. A good tip is to do a type of quality distribution of your data and use the best, even if they are not exactly registered. See the examples below.

Example:

You are using the Hippocampus atlas brains and labels (5). Check each label file (registration) starting with brain1, then eliminating "bad" templates sequentially:

brain1: 30 fails -> 70 remaining

brain2: 20 fails -> 50 remaining

brain3: 15 fails -> 35 remaining

brain4: 10 fails -> 25 remaining

brain5: 3 fails -> 22 remaining -> take 21 from here, use as final template library.

Remember to uncheck (remove the #) the lines of code in the mb script so you can run MAGeT afterwards.

Some TIPS from the CobraLab Crew.

These tips may help you decide which are the best templates. It is not a standardised method yet, but it will make your labelling for MAGeT much better.

Here is a quote from Matt himself:

"I've found this approach works very well with datasets that don't match/register very well to our atlases & significantly improves overall segmentation accuracy. I don't even check the demographic/DX spread of the resulting template library, but in cases where there is significant degen. (i.e. large ventricles)- I try to choose "intermediate"-anatomy subjects (as in intermediate anatomy/ventricle size between our atlases & heavily degen. subjects) that pass template QC. This approach was especially effective for ADNI1/ADNI2GO- I specifically chose ~200 candidate subjects, that were either MCI or AD within ADNI1/ADNI2GO- only ~25-30 from the initial 200 passed all pairwise atlas-to-template QC (just out of pure chance, really). Chose the final 21 from these, and the final subject labels were freakin excellent, to the point that they almost did not need QC-ing for the hippocampus.

For example, let's say (after template QC) you end up with the following template candidates:

20 subjects with small ventricles: pass 10 patients with medium-sized ventricles: pass 3 patients (out of maybe ~20) with large ventricles: pas

Here, I would try to choose subjects from the latter two (10 + 3) and 8 from the small ventricle group- that way, you get optimal "matching" between templates and subjects, pairwise amongst all "subtypes" of anatomy present in the dataset. It's difficult to do in small samples (limited N), but I find that even proceeding with simply controls (small ventricles) that pass QC still works reasonably well, as you're still minimizing error at the template stage & templates generally register quite well to subjects since they're usually from the same acquisition."

Here is a quote from Raihaan:

One thing to note is that these are labels produced from a single atlas registration, so the overall quality will be noticeably poorer than final maget output. So your definition of 'good' will likely be more lenient than if you were qcing final maget output. I usually find a distribution in quality when I do this, and I just try to take the nicest ones. Sometimes the nicest ones are great, and sometimes the nicest ones are not so great but they are the best I have.

Example of a bad registration:

Example of good registration:


Clone this wiki locally