source("glossary_setup.R")
3 Quality control
As quality control goes, this is not exhaustive, but here is my suggestion as to a minimum approach.
On paper, everything is now done. But of course, you should go through all subjects manually to check that, the masking went well, as that is the real key step in this process.
Sticking to the broader lines, the problems may be of either auto-cropping or masking. As masking goes, the script may have included too much or too little in the brain mask. I’ll go through suggested solutions to all these below.
3.1 Inspection
I have come to like the ITK-SNAP tool, but fsleyes is good as well.
I would open the new “SubNN_T1w.nii.gz” in fsleyes or ITK-SNAP and overlay the “SubNN_T1w_brain_mask.nii.gz” and go through to check the masking and cropping. Check the cropping and the masking. Happy? Carry on to the next subject. Not so much? See below.
3.2 Cropping
Do not skip this step. Take a good look at the cropping, as the algorithm might have cropped out part of cerebellum (typically the issue, if any).
Delete all the output-files (remembering that the original files were preserved with “_orig” suffix) and renaming the original files removing the suffix.
Open the original T1 image and lesion mask in fsleyes, and manually crop the two with the same mask when cropping, you can save the crop mask from the T1 and load it for the lesion mask). If the two files are not cropped to the same dimensions, they won’t align, and you’ll be in trouble.
After cropping, run the
00nemo_prep_pipeline.sh
script again. It will only run in folders with the *.anat folder not present.
3.3 Masking
In ITK-SNAP, you can correct the brain mask manually. Overall, open the “SubNN_T1w.nii.gz” with and the “SubNN_T1w_brain_mask.nii.gz” with . You can manually edit the brain mask by using the interpolate tool to apply changes to all layers in all three planes. Please have a look at this demonstration of the tool. Make sure that changes are made in a different label to the main label of the brain mask segmentation.
Here, I’ll just go through an order of work for the two different cases:
3.3.1 Too little
This is simple. You just add the missing:
- Using the drawing tool, include the missing parts of the brain/infarct in the new label. You can get by by just drawing on each 5-7 layers in the axial plane. Then do interpolate along the axial axis. Check that you are satisfied. If not, then . Add a few other layers of manual drawing. Interpolate again. When done, save as a new file.
3.3.2 Too much
This is also relatively simple, but has an extra step:
Invert the lesion mask:
fslmaths SubNN/SubNN_T1w_brain_mask.nii.gz -binv SubNN/SubNN_T1w_brain_mask_INV.nii.gz
Follow the same steps as above to add non-brain area to exclude from the brain mask. Save the new brain mask and then invert the modified inverted brain mask again:
fslmaths SubNN/SubNN_T1w_brain_mask_INV.nii.gz -binv SubNN/SubNN_T1w_brain_mask_MODIFIED.nii.gz
Check that you are satisfied with the result.
3.3.3 Register to MNI space again
Having a new, modified brain mask, go to the terminal window again and write the following:
sh modified_brain_mask_bbl.sh SubNN/SubNN_T1w.nii.gz SubNN/SubNN_T1w_brain_mask_MODIFIED.nii.gz
Please notice that the naming of the modified brain mask doesn’t matter.
3.4 Final quality control steps
After registering the lesion mask to standard space, please make sure, that you are satisfied with the result. You might have to correct to masking, especially if its a large lesion. In my experience, the common problem is that the algorithm have left out some of the infarcted area towards cortex. In ITK-SNAP you can add this area. If the lesion is all the way to the surface of the cortex, then make sure to overfill towards the surface (into the non-brain area). Afterwards, you can perform a three step approach to “punch” out the lesion only to the surface of the brain.
The following will create an inverted MNI brain mask in you source directory. Make sure that the fsl directory is correct.
fslmaths /usr/local/fsl/data/standard/MNI152_T1_1mm_brain_mask.nii.gz -binv mni_1mm_brain_mask_inv.nii.gz
The next is the short version of a three-step operation to 1) make sure the lesion mask is binary, 2) subtract the inverted MNI brain mask as an inverted hole-puncher, and finally 3) using the threshold function to isolate the lesion mask. Please correct the subfolder and file names.
fslmaths subNN/subNN_T1w_MNI-1mm_lesion.nii.gz -bin -sub mni_1mm_brain_mask_inv.nii.gz -thr 0 subNN/subNN_T1w_MNI-1mm_lesion_punch.nii.gz
Now please rename the old MNI lesion mask and remove the “_punch” suffix from the new lesion mask name to follow the standard naming.
If you are performing several of the “punch-out” actions, I have created a small script other/multi-punch.sh
, that will automate this process a bit. To run it, you provide a folder name to search and a common regex pattern to search for within the folder (it includes with sub-folders). The syntax would be like this:
sh multi-punch.sh /sourcefolder "*_lesion.nii.gz"
3.5 Glossary
term | definition |
---|---|
fsleyes | Thes picture viewing tool from the fsl-package. https://fsl.fmrib.ox.ac.uk/fsl/fslwiki/FSLeyes |
regex | Short of Regular Expression. Provides a very powerful character search interface. There are various resources online for [learning](https://www.sitepoint.com/learn-regex/) and [validating](https://regex101.com/) your regex search pattern. |