Skip to content

MAGeT Brain Related Masking

ericplitman edited this page Mar 12, 2020 · 1 revision

This wiki describes the steps to:

  1. Mask a MAGeT Brain atlas
  2. Modify a MAGeT Brain atlas to only include certain labels
  3. Mask a MAGeT Brain output label using bpipe output

Mask a MAGeT Brain atlas

I've found this step to be useful for situations where I am seeing large over-segmentation (particularly in striatum labels)

ThresholdImage 3 brain1.mnc otsu1.mnc Otsu 1

mincresample -keep -near -byte -like brain1_labels.mnc otsu1.mnc otsu1mod.mnc

mincmath -2 -mult brain1_labels.mnc otsu1mod.mnc brain1_labels_mod.mnc

Note: Remember that you will have to do this for each label file. Also, remember that the name of your label files needs to be in line with the name of the corresponding brain. So, you would likely not want it to be brain1_labels_mod.mnc and instead to be brain1_labels.mnc (corresponding to brain1.mnc).

Modify a MAGeT Brain atlas to only include certain labels

I've found this useful for breaking the subcortical atlas into separate structures that are left-right split.

If you want only the left striatum:

minclookup -discrete -lut_string "1 1; 2 0; 3 0; 4 0; 5 0; 6 0;" brain1_labels.mnc X_brain1_labels.mnc

If you want only the left globus pallidum:

minclookup -discrete -lut_string "1 0; 2 1; 3 0; 4 0; 5 0; 6 0;" brain1_labels.mnc X_brain1_labels.mnc

If you want only the left thalamus:

minclookup -discrete -lut_string "1 0; 2 0; 3 1; 4 0; 5 0; 6 0;" brain1_labels.mnc X_brain1_labels.mnc

If you want only the right striatum:

minclookup -discrete -lut_string "1 0; 2 0; 3 0; 4 1; 5 0; 6 0;" brain1_labels.mnc X_brain1_labels.mnc

If you want only the right globus pallidum:

minclookup -discrete -lut_string "1 0; 2 0; 3 0; 4 0; 5 1; 6 0;" brain1_labels.mnc X_brain1_labels.mnc

If you want only the right thalamus:

minclookup -discrete -lut_string "1 0; 2 0; 3 0; 4 0; 5 0; 6 1;" brain1_labels.mnc X_brain1_labels.mnc

#Remember that you will have to do this for each label file. Also, remember that the name of your label files needs to be in line with the name of the corresponding brain. So, you would likely not want it to be X_brain1_labels.mnc and instead to be brain1_labels.mnc (corresponding to brain1.mnc).

Mask a MAGeT Brain output label using bpipe output

INFILE=$1
VOLDIR=~/scratch/komagino_allants/Mask_Test/preprocessed/bpipe-outputs

VOLSUFFIX=.convert.n4correct.cutneckapplyautocrop.brainvolume.mnc

OUTDIR=~/scratch/komagino_allants/Mask_Test/striatum_left_majority_vote

FILENAME=$(basename $INFILE .convert.n4correct.cutneckapplyautocrop.beastextract_labels.mnc)

echo $FILENAME

# Ensure brain volume and labels have the same dimensions
mincresample -like $INFILE $VOLDIR/${FILENAME}$VOLSUFFIX $OUTDIR/${FILENAME}_resampled.mnc

# Mask
mincmath -2 -mult $INFILE $OUTDIR/${FILENAME}_resampled.mnc $OUTDIR/${FILENAME}_labels.mnc

Note: save the above as a .sh. As an example of how it can be run: for file in *; do bash ~/scratch/komagino_allants/Mask_Test/mask_apply.sh $file; done

Clone this wiki locally