# Tracts group mask

**URL:** <https://community.mrtrix.org/t/tracts-group-mask/297>\
**Category:** Uncategorized\
**Created:** [June 14, 2016, 9:54am UTC](https://community.mrtrix.org/t/tracts-group-mask/297 "2016-06-14T09:54:48Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hamed](https://community.mrtrix.org/user_avatar/community.mrtrix.org/hamed/32/2871_2.png) [@Hamed](https://community.mrtrix.org/u/Hamed)\
**Post date:** [June 14, 2016, 9:54am UTC](https://community.mrtrix.org/t/tracts-group-mask/297/1 "2016-06-14T09:54:49Z")

</div>

Dear Experts

I have my tracts in MNI space and want to create a group mask for a particular tract. I found this

$ tracks2prob yourtracks.tck -template fa.mif - | threshold - -abs 5 - | mrstats fa.mif -mask -

which I guess is from MRtrix2. Is there any command in mrtrix3 that would do the same job?

Cheers,  
Hamed

---

<div class="post-metadata">

**Author:** ![jdtournier](https://community.mrtrix.org/user_avatar/community.mrtrix.org/jdtournier/32/2594_2.png) [@jdtournier](https://community.mrtrix.org/u/jdtournier)\
**Post date:** [June 14, 2016, 11:17am UTC](https://community.mrtrix.org/t/tracts-group-mask/297/2 "2016-06-14T11:17:49Z")

</div>

The equivalent in MRtrix3 would be:

```
$ tckmap yourtracks.tck -template fa.mif - | mrthreshold - -abs 5 - | mrstats fa.mif -mask -
```

---

<div class="post-metadata">

**Author:** ![Hamed](https://community.mrtrix.org/user_avatar/community.mrtrix.org/hamed/32/2871_2.png) [@Hamed](https://community.mrtrix.org/u/Hamed)\
**Post date:** [June 14, 2016, 11:48am UTC](https://community.mrtrix.org/t/tracts-group-mask/297/3 "2016-06-14T11:48:15Z")

</div>

Thanks Donald

Could you please provide a bit of summary about what it does exactly with - | threshold - -abs 5 - | mrstats fa.mif -mask -?

Cheers,  
H

---

<div class="post-metadata">

**Author:** ![jdtournier](https://community.mrtrix.org/user_avatar/community.mrtrix.org/jdtournier/32/2594_2.png) [@jdtournier](https://community.mrtrix.org/u/jdtournier)\
**Post date:** [June 14, 2016, 12:54pm UTC](https://community.mrtrix.org/t/tracts-group-mask/297/4 "2016-06-14T12:54:45Z")

</div>

The syntax used here relies on Unix pipes, which are [explained in some detail here](http://mrtrix.readthedocs.io/en/latest/getting_started/command_line.html#unix-pipelines). This particular chain of commands takes the output of `tckmap` and thresholds it at an absolute value of 5, producing a binary image with value 1 where the track count exceeds 5, and 0 otherwise. The output of that is then fed to `mrstats` to be used as the `-mask` argument, meaning `mrstats` will provide statistics for the FA map within voxels with track count higher than 5.

I hope this clarifies what’s going on…?

---

<div class="post-metadata">

**Author:** ![Hamed](https://community.mrtrix.org/user_avatar/community.mrtrix.org/hamed/32/2871_2.png) [@Hamed](https://community.mrtrix.org/u/Hamed)\
**Post date:** [June 15, 2016, 7:49am UTC](https://community.mrtrix.org/t/tracts-group-mask/297/5 "2016-06-15T07:49:41Z")

</div>

Thanks Donald,

Actually I would like to know your comments on what I am doing if it makes sense.  
I perform tractography between M1-CC-M1 in subject space and then bring the tracts to MNI space in order to create a group mask (with some thresholding) which will be transformed back to individual space in order to have the stats.

Do you think this is correct approach?

Cheers,  
H

---

<div class="post-metadata">

**Author:** ![jdtournier](https://community.mrtrix.org/user_avatar/community.mrtrix.org/jdtournier/32/2594_2.png) [@jdtournier](https://community.mrtrix.org/u/jdtournier)\
**Post date:** [June 16, 2016, 12:33pm UTC](https://community.mrtrix.org/t/tracts-group-mask/297/6 "2016-06-16T12:33:33Z")

</div>

That depends on exactly what you’re trying to do, but assuming you’re trying to measure e.g. FA along/within tracts, you should take a look at [tcksample](http://mrtrix.readthedocs.io/en/latest/reference/commands_list.html#tcksample) and [tckresample](http://mrtrix.readthedocs.io/en/latest/reference/commands_list.html#tckresample). There used to be an option to allow the sample positions to be defined in template space, but things have changed a bit as of [today’s version update](https://community.mrtrix.org/t/mrtrix3-version-incremented-to-0-3-15/300/1), so I’m not sure what the process is now. @rsmith should be able to fill in the gaps…

---

<div class="post-metadata">

**Author:** ![rsmith](https://community.mrtrix.org/user_avatar/community.mrtrix.org/rsmith/32/2672_2.png) [@rsmith](https://community.mrtrix.org/u/rsmith)\
**Post date:** [June 17, 2016, 12:22am UTC](https://community.mrtrix.org/t/tracts-group-mask/297/7 "2016-06-17T00:22:09Z")

</div>

I think we should break this up into sections to avoid confusion. I’ll lay down some suggestions, but bear in mind this isn’t a ‘unique’ answer, and exactly how you do these steps will influence the result you get.

1. Transform subject tracks to template space: `tcknormalise`
2. Generate a mask in template space _per subject_: `tckmap` to generate the TDI, followed by `mrthreshold` to apply a threshold and produce a mask
3. Compute the ‘group average’: I’m going to assume this corresponds to voxels where more than some percentage of subjects have a track count higher than the threshold from step 2. `mrmath` using the `sum` operator across subject masks, then `mrthreshold`
4. Transform ‘group average’ mask to subject space: `mrtransform`
5. Compute the mean FA within this mask: `mrstats -mask`

An approach using the new `tcksample` and `tckresample` as @jdtournier suggested would look quite different, and I can think of more than one way to do it. But it would probably be something along the lines of:

1. Define tracking targets in template space.
2. Transform ROIs to subject space: `mrtransform`
3. Use ROIs to select streamlines of interest in subject space: `tckedit`
4. Calculate mean FA along each streamline: `tcksample -stat_tck mean`
5. Take the average across all streamlines

One obvious difference between the two approaches is that when using the mask approach, all voxels within the mask contribute equally to the result; that is, voxels at the outer edge of the bundle contribute just as much as those smack bang in the middle. With the `tcksample` approach, each _streamline_ contributes equally, and therefore the FA in those voxels in the middle of the bundle will have a greater influence on the result than those at the outer edges.

> There used to be an option to allow the sample positions to be defined in template space

Yes, I think I left that out in favour of doing such operations in steps, i.e. with `tcknormalise`. The old `tcksample` was kind of three operations merged into one command, which didn’t leave much wiggle room; and the old `-warp` option only ensured equidistant points in template space, which isn’t actually required here. I think when I eventually do track data piping, this approach will make a lot more sense, and be clearer about what’s happening and in what order.

---

<div class="post-metadata">

**Author:** ![Hamed](https://community.mrtrix.org/user_avatar/community.mrtrix.org/hamed/32/2871_2.png) [@Hamed](https://community.mrtrix.org/u/Hamed)\
**Post date:** [June 17, 2016, 12:19pm UTC](https://community.mrtrix.org/t/tracts-group-mask/297/8 "2016-06-17T12:19:48Z")

</div>

Thanks Rob for the clarification.  
I think the advantage of the 1st approach is to get rid of those small number of unwanted streamlines by thresholding and have the same voxels for all subjects. For the 2nd approach maybe less number of transformations and less interpolation?

Cheers,  
H

---

<div class="post-metadata">

**Author:** ![rsmith](https://community.mrtrix.org/user_avatar/community.mrtrix.org/rsmith/32/2672_2.png) [@rsmith](https://community.mrtrix.org/u/rsmith)\
**Post date:** [June 20, 2016, 3:49am UTC](https://community.mrtrix.org/t/tracts-group-mask/297/9 "2016-06-20T03:49:55Z")

</div>

Could probably write an entire article on the precise behaviour of different approaches for this kind of problem 😛

Approach 1 requires defining two thresholds: one for thresholding the per-subject TDI in template space, and one for determining how to generate the group average mask from these. Tweaking either of those numbers will influence the extent of the group average mask, and therefore the final result. Saying it has the ‘same voxels for all subjects’ is not quite accurate: they’re the same voxels _in template space_, but how these map back to subject space (where the FA is actually sampled) is entirely subject-specific.

With Approach 2, the main issue is the definition of those tracking targets, how they map to subject space, and the extent to which unwanted streamlines get included in the result. But it has the advantage that you’re delineating the pathway of interest in subject space and sampling the underlying values directly, rather than taking samples from where you _think_ the pathway is based on a group template. And it gives greater weighting to voxels in the bundle core and less at its outer extremities.

But maybe I’m biased because I want people to use the new toys I just gave them 😏

Rob

---

<div class="post-metadata">

**Author:** ![Hamed](https://community.mrtrix.org/user_avatar/community.mrtrix.org/hamed/32/2871_2.png) [@Hamed](https://community.mrtrix.org/u/Hamed)\
**Post date:** [June 27, 2016, 12:33pm UTC](https://community.mrtrix.org/t/tracts-group-mask/297/10 "2016-06-27T12:33:10Z")

</div>

Dear Rob

I’ve started with the first approach and later will try the second one as well. I have 2 questions regarding the first approach.  
In the tckgen, I included my left M1 seed region, include (CC) and exclude (e.g., midline) masks and will repeat this with my right M1 seed region.

1. What is the general advice for the -maxnum and -number options of tckgen in this case?
2. For 2 groups of Young and Old healthy participants would you create a mask for all participants, or one per group, or only for the Young which can be used for both groups.

Thanks and cheers,  
H

---

<div class="post-metadata">

**Author:** ![rsmith](https://community.mrtrix.org/user_avatar/community.mrtrix.org/rsmith/32/2672_2.png) [@rsmith](https://community.mrtrix.org/u/rsmith)\
**Post date:** [June 28, 2016, 11:49pm UTC](https://community.mrtrix.org/t/tracts-group-mask/297/11 "2016-06-28T23:49:02Z")

</div>

Hi again Hamed,

1. How long is a piece of string? 😛 There’s never a simple answer to this one. But a couple of heuristics I like to go by:

- If you can see individual streamlines in your pathway of interest (i.e. not counting spurious streamlines), you don’t have enough streamlines.
- If repeating the tracking experiment on the same image data does not give reproducible results (due to the probabilistic nature of tracking), you don’t have enough streamlines.
- When your colleagues begin complaining about you abusing the lab’s computing resources, you have _just enough_ streamlines 😛

1. This is really more of an experiment design question, so I’m limited here without knowing all the ins & outs of the experiment. But my general sense is:

- If the pathway has a measurable difference in extent between the two groups, and your derivation of the relevant masks would differ between the two groups, then use different masks.
- _Unless_ you plan on performing some direct comparison between the two groups, in which case you _must_ use the same masks between them in order to remain unbiased; and you would want to use an equal number of subjects from both groups when deriving the masks.

Cheers  
Rob

---

<div class="post-metadata">

**Author:** ![Hamed](https://community.mrtrix.org/user_avatar/community.mrtrix.org/hamed/32/2871_2.png) [@Hamed](https://community.mrtrix.org/u/Hamed)\
**Post date:** [June 29, 2016, 9:24am UTC](https://community.mrtrix.org/t/tracts-group-mask/297/12 "2016-06-29T09:24:33Z")

</div>

Hi Rob

Thank you for your patience regarding my (maybe 🙂 ) naive questions.  
I will continue with the first approach to see what it produces.

Cheers,  
H
