Mrthreshold percentile

Hi all!

I am quite new to MRTRIX and doing a tractography project from subcortical to cortical regions. I have a question about mrthreshold. I want to use a 95% cut-off value, so the 5% of tracts with the lowest intensity are filtered out (which were going into the opposite hemisphere or into the brainstem), but when I try this with the -percentile flag, I get no tracts at all. This is the code I used:

mrthreshold from_NbM_to_1-2.nii.gz threshold2.nii.gz -percentile 0.95

Does anyone know what went wrong and has an example code for me? Or if you know another way to threshold with % instead of values, please let me know :slight_smile:

Thanks in advance!
Best,
Senne

Hi Senne

This wasn’t obvious to me immediately either (maybe the documentation could be tweaked…), but I can see a couple things that might be causing the issue.
Firstly, the syntax for the 95th percentile (95%) would be -percentile 95 rather than decimal notation, I believe.
Secondly, even using that syntax, you might still get nothing useful if the vast majority of your voxels are 0, so using the -ignorezero flag you can calculate your intensity threshold based only off the voxels with non-zero value to begin with.
Finally, if you want to set the upper 95% of intensity values to 1 and the the lower 5% to 0, then you would need to use the threshold value -percentile 5, i.e. your cutoff value is at the 5th percentile.

Assuming by “tracks” here you are referring to individual voxels in a track density image (correct me if I’ve misunderstood!) I’m not entirely sure this is even possible with mrthreshold -percentile. This is because the -percentile option is used to determine the threshold value, rather than the number of voxels that will be set to 0 in the output.

So I had a look at a random track density image as an example, and (assuming -ignorezero), 26% of voxels had intensity of 1. So I could call mrthreshold -comparison gt -percentile x using any value between 0 and 26 for x and the output would look the same, because the threshold would be set at intensity 1 and all of those 26% of voxels would be filtered out. You would get the same behaviour even if specifying a number of voxels e.g. using -bottom, albeit with a warning:

mrthreshold: [WARNING] Duplicate image values surrounding threshold; exact number of voxels influenced by numerical threshold may not match requested number

Maybe this is the functionality you wanted all along and I simply misunderstood!

I hope that’s helpful and not just more confusing!
Fiona