# Automatically defining spinal-cord ROI for custom parcellation

**URL:** <https://community.mrtrix.org/t/automatically-defining-spinal-cord-roi-for-custom-parcellation/7022>\
**Category:** Uncategorized\
**Tags:** connectomics, tractography\
**Created:** [October 18, 2023, 9:48am UTC](https://community.mrtrix.org/t/automatically-defining-spinal-cord-roi-for-custom-parcellation/7022 "2023-10-18T09:48:13Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![ecla](https://community.mrtrix.org/letter_avatar_proxy/v4/letter/e/e9a140/32.png) [@ecla](https://community.mrtrix.org/u/ecla)\
**Post date:** [October 18, 2023, 9:48am UTC](https://community.mrtrix.org/t/automatically-defining-spinal-cord-roi-for-custom-parcellation/7022/1 "2023-10-18T09:48:13Z")

</div>

Hi there experts!

I’m performing anatomically constrained tractography with 5 tissue type images generated by 5ttgen hsvs. I have come up with a way to add 2 ROIs to the parcellation scheme: the brainstem and the spinal cord (the bottom few voxels of the brainstem).

 ![Screenshot 2023-10-18 at 8.07.07 PM](https://community.mrtrix.org/uploads/default/original/2X/a/a740764864fc37da17a0bd6d9da14eabff1cbb0e.png)

My method seems to do the job but I was wondering if anyone could help me make my method more robust.

```
labelconvert $fs_dir/mri/aparc+aseg.mgz $FREESURFER_HOME/FreeSurferColorLUT.txt .../fs_default_brainstem.txt dk_BS_parcel.mif # Using a custom LUT to add brainstem to DK parcellation. 

mrtransform dk_BS_parcel.mif -linear T1_rig_dwi.txt -datatype uint32 dk_BS_parcel_coreg.mif # Transforming parcellation image to DWI

5tt2vis T1_5tt_coreg.mif 5ttvis.mif

mrthreshold 5ttvis.mif -abs 2 - | mrgrid - regrid -template dk_BS_parcel_coreg.mif brainstem_pad_5tt.mif -datatype bit # Mask of brain stem included in 5ttgen image. 

mrthreshold dk_BS_parcel_coreg.mif -abs 85 - | maskfilter - erode -npass 2 brain_parcel_erode.mif # Mask of brainstem from FreeSurfer eroded to make all voxels are within brainstem_pad_5tt.mif

mrcalc brain_parcel_erode.mif brainstem_pad_5tt.mif -subtract brain_parcel_erode.mif -mul - -datatype bit | maskfilter - dilate -npass 5 spinal_cord_dilate.mif # Mask of brain stem not included in 5ttgen image, dilated to include bottom portion of brain-stem segmentation. 

mrcalc dk_BS_parcel_coreg.mif 85 -eq spinal_cord_dilate.mif -mul 1 86 -replace dk_BS_parcel_coreg.mif -max dk_BS_SC_parcel_coreg.mif # Adding the bottom portion of brain-stem segmentation back to parcellation image.

```

 ![Screenshot 2023-10-18 at 10.20.19 PM](https://community.mrtrix.org/uploads/default/original/2X/6/6ef031ffdeaa72bf5a69f54a701d500001ff7bd1.png)  
 ![Screenshot 2023-10-18 at 10.19.26 PM](https://community.mrtrix.org/uploads/default/original/2X/b/be92e1283f764c91e2e3da34e568e7d4a082f096.png)  
 ![Screenshot 2023-10-18 at 10.39.46 PM](https://community.mrtrix.org/uploads/default/original/2X/5/5c94a4c0880588786b0914c32794c4083f94b744.png)

For those interested, this paper [Connectomes from streamlines tractography: Assigning streamlines to brain parcellations is not trivial but highly consequential - PubMed](https://pubmed.ncbi.nlm.nih.gov/31082471/) by Chun-Hung Yeh , Robert E. Smith, Thijs Dhollander, Fernando Calamante, and Alan Connelly gave me the idea.

Many thanks!

Ed
