ROIs from atlas to generate ROI to ROI streamlines

Hi there,

I would like to use tckgen to generate streamlines between two rois. I have the atlas (the parcellation) and I also have performed tckgen for the whole brain but I would like to just seed streamlines between two rois and use that instead of tck2connectome and then select the specific ROIs. The reasoning is that I keep having issues with rois not having assigned streamlines within the subthalamic nucleus for a number of subjects while other subjects appear to have no issues.

Is there a way to do this without generating many masks for each subject?


1 Like

Hi @Benjamin_Deck ,
You can use -include or -include_ordered option of the tckgen
command. I hope this helps.
Many Thanks,

Hi Benjamin,
Just as Suren said, -include is a suitable option.
Since you have the whole brain tractography, I recommend using tckedit which runs much faster than generating new streamlines and can save time.

The following content is quoted from the MRtrix3 docs, hope it helps. :grinning:


  • Extract streamlines based on selection criteria:
tckedit in.tck out.tck -include ROI1.mif -include ROI2.mif -minlength 25

Multiple criteria can be added in a single invocation of tckedit, and a streamline must satisfy all criteria imposed in order to be written to the output file. Note that both -include and -exclude options can be specified multiple times to provide multiple waypoints / exclusion masks.

  • Select only those streamline vertices within a mask:
tckedit in.tck cropped.tck -mask mask.mif

The -mask option is applied to each streamline vertex independently, rather than to each streamline, retaining only those streamline vertices within the mask. As such, use of this option may result in a greater number of output streamlines than input streamlines, as a single input streamline may have the vertices at either endpoint retained but some vertices at its midpoint removed, effectively cutting one long streamline into multiple shorter streamlines.

@suren @StarVolcano

Thank you both for your replies.

Hmm, I believe this would still involve generating a number of masks.

Is there something similar to connectome2tck -nodes that can be used to seed streamlines?

In other words, I don’t want to generate the masks and wondering if there is a workaround.


Hi Ben

Are you trying to avoid creating ROI masks because of the amount of effort involved, or for some other reason e.g. saving storage?

If it’s just about the effort, maybe this thread about automatically creating ROIs based on atlas parcellation indices might be useful? If you know the label values for the nodes you want connections for, it’s fairly straightforward to do what (I think?) you’re trying to achieve.

e.g. say you have a parcellation (in subject space) called parc.nii.gz and the ROIs you’re interested in are labelled 1 and 2. Then you can get streamlines between those two nodes as @StarVolcano and @suren suggested:

mrcalc parc.nii.gz 1 -eq seed.nii.gz
mrclac parc.nii.gz 2 -eq end.nii.gz
tckgen fod.mif -seed_image seed.nii.gz -include end.nii.gz -stop out.tck
# Or using existing whole brain tck file
tckedit wbt.tck -include seed.nii.gz -include end.nii.gz

But if you don’t want to retain lots of mask files you could use bash piping (on unix) to make them temporary files:

tckgen fod.mif -seed_image $(mrcalc parc.nii.gz 1 -eq -) -include $(mrclac parc.nii.gz 2 -eq -) -stop out.tck

If you’re really adamant about not using any inclusion or seed mask files, then I can’t think of an alternative workaround I’m afraid. And sorry for being the 3rd person suggesting the thing you really don’t want to do!



Hi, Ben:

As Fiona said, I tried to do something similar in the past. If you still have questions, contact me on my Uni email, and I’ll try to answer you the best I can!

1 Like

@Marcos_Uceta_Garcia @fionaEyoung @jdtournier

Hi there,

So I applied the solution that you guys suggested. I have masks for the globus pallidus pars externa, dorsal striatum, and subthalamic nucleus for each hemisphere.

My command then takes these masks and generates a constrained .tck file using the following command.

  tckedit ${orig_tck_file} \
  /Volumes/833850_ADHD/UCLA_consortium/roi_analysis/final_tck_files/${sub}/${hemi}ds_${hemi}gpe_${hemi}stn.tck \
  -tck_weights_in ${weights_file} \
  -include ${ia_masks}/${hemi}ds_seed_mask.nii.gz \
  -include ${ia_masks}/${hemi}gpe_mask.nii.gz \
  -include ${ia_masks}/${hemi}stn_mask.nii.gz \
  -minlength 25 \
  -nthreads 25

Which produces a track file which is a little more encompassing than I would have hoped. This should only be the left hemi and only tracks between these three seeds.

However, as you can see from the image attached, the tracks are pulled from a large number of spaces. The mask files look good, though. which can be seen in this image: — Red = Dorsal striatum (caudate putamen), blue = globus pallidus pars externa, green/yellow = subthalamic nuclues

I am thinking if I apply -mask to each roi this will give me a more conservative estimate but I am worried it won’t capture the tracks that pass between the rois and only the tracks within the mask. Am I thinking about this incorrectly?


I used the -mask flag:

tckedit lds_lgpe_lstn.tck \
constrained_tck -tck_weights_in /Volumes/833850_ADHD/UCLA_consortium/qsi_recon/sub-10171/dwi/sub-10171_space-T1w_desc-preproc_desc-siftweights_ifod2.csv \
-mask /Volumes/833850_ADHD/UCLA_consortium/roi_analysis/masks/sub-10171/ia_analysis/final_masks/lds_seed_mask.nii.gz \
-mask /Volumes/833850_ADHD/UCLA_consortium/roi_analysis/masks/sub-10171/ia_analysis/final_masks/lstn_mask.nii.gz\
 -mask /Volumes/833850_ADHD/UCLA_consortium/roi_analysis/masks/sub-10171/ia_analysis/final_masks/lgpe_mask.nii.gz \
-minlength 25

And it indeed produced the tracts within the masks, but not between the masks


Any thoughts?!

Hi Ben:

I encountered the same problem when I first started. I had to possible solutions:

  1. Use a binary mask for one hemisphere (right or left) and use it for -exclude on the tckgen in order to mask the parts you don’t want the tracks to go.
  2. Binary, compartimentalize and make all the mask more restricted, until the tracts that start appearing are shorter, narrower tracts. That will reduce the possibilities of unwanted tracts.

Remember that this method is a probabilistic method. Some tracts might appear even if they are not biologically supported.

Hope my comments helped.


The -mask option works well, but the problem is it masks out the connections that I care about, the between roi connectivity. Is there a way to do this that is more conservative?

I have also used the SIFT2 mechanism and included the track weights.

The mask option isn’t really suitable in this context, since it will simply truncate any streamlines that exit the mask. The streamlines you’re seeing may well have connected between your ROIs, but the use of -mask will clip off the parts outside of the mask, does that make sense? So you could create a mask encompassing all of your ROIs, but that doesn’t mean that the streamlines you’ll see originally remained within that mask, you’re just hiding the bits that didn’t!

The streamlines selected using -include only have to pass through your regions of interest at a minimum. As long as a streamline touches each of your masks, it’s free to go wherever else it pleases!
So your initial results are what you would expect, since the sreamlines passing through your ROIs are likely to visit other parts of the brain. (As Marcos points out, in probabilistic tractography, most generated streamlines are probably going to be “wrong” one way or another.)

If you only want to see streamlines that terminate in a specific ROI you could try the -ends_only flag, but I’m not sure how you would make that work with 3 ROIs, when a streamline only has 2 ends! You’d probably have to do the different combinations separately e.g.

tckedit wbt.tck -include A.nii.gz -include B.nii.gz -ends_only A_to_B.tck
tckedit wbt.tck -include B.nii.gz -include C.nii.gz -ends_only B_to_C.tck
# etc

You could also try specifying a -maxlength to narrow your results down to shorter streamlines local to your ROIs.

Ultimately you’ll be limited by whatever streamlines are already present in your whole-brain tractography, so the parameters used to generate those may or may not have been optimal for seeing the connections you’re interested in. Short streamlines in particular around that area are unlikely to be abundant - in particular any streamline passing through your dorsal striatum ROI is on a fast track to the entire frontal lobe! Again, specifying a -maxlength at this stage might help, but would be computationally pretty wasteful.*

I would be careful about about constraining and wrestling your streamlines too much though, otherwise you risk your results becoming uninterpretable. To paraphrase a great scholar: “If you torture your tractography algorithm, it’ll tell you anything!”

*if my interpretation of -maxlength is correct, that it discards any tracks that exceed the limit, rather than truncating them.