Tckgen - error negative values


I tried executing an ACT tractography with tckgen, but stumbled on the following error:
[ERROR] Cannot have negative values in an image used for rejection sampling.

This is the command line I used:
tckgen ${results}.fodf.nii ${results}/tracks_act_extra.tck -act ${results}.5tt.nii -backtrack -crop_at_gmwmi -seed_gmwmi ${results}/gmwmi.nii -number 10000000 -fslgrad ${results}/bvecs ${results}/bvals

I am not sure what caused this error. The steps were followed as described in the ACT tutorial & non-ACT tractography can be performed without errors.

Thanks for any help!

That’s a slightly strange problem to have encountered for a fairly basic workflow.

The ‘initial’ determination of seed points in the GM-WM interface seeder (before they are moved precisely to the interface) is performed using rejection sampling. This allows the seeding density to be specified using a floating-point image rather than a mask, which helps to alleviate some unusual artefacts related to non-homogeneous interface seeding that otherwise arise from use of a voxel grid rather than a mesh representation.

The basic mechanism is as follows:

  • Use an image where the intensities range from 0 up to some maximum. Pre-calculate this maximum value.
  • Each time a new seed point is requested:
    • Select a voxel at random.
    • Generate a random number, ranging from 0 up to the maximum image intensity.
    • If the random number is less than the image intensity in that voxel, use that voxel as a streamline seed. If not, repeat the process until a suitable seed is selected.

What this error is suggesting is that the image provided by the 5tt2gmwmi command contains negative values - which don’t make sense in the algorithm described above. This shouldn’t happen given the way this image is calculated, but somehow it has. You can confirm this by running: mrstats gmwmi.nii. You can also see where these negative values are, using: mrcalc gmwmi.nii 0.0 -lt - | mrview gmwmi.nii -overlay.load -.

I can’t really think of any advice I can give without being able to see the files for myself. If you’re unable to figure out what has caused the issue by examining the 5TT and gmwmi images, you’ll need to send me a pair of example images so that I can dig further.

Best regards

I tried the commands you suggested, indeed the mask contains some negative values:
mrstats gmwmi.nii
volume mean median std. dev. min max count
[ 0 ] 0.0150488 0 0.0808404 -0.000275259 0.866239 9502720

Would there be a way to fix it? Apart from the negative values the mask appears to be accurate.

Thanks for letting me know: I’ll look into why this might be occurring and implement a fix.

In the meantime, the easiest way to fix the problem for your data is to do something like:
mrcalc gmwmi.nii 0.0 -max gmwmi_fix.nii
That will clamp the negative values to zero, so that tckgen should accept it as a GMWMI seed.


Out of curiosity: Is there anything unusual about your 5TT / GMWMI images, particularly with respect to the data type / scaling? Calculation of the GMWMI image values is based on a square-root sum-of-squares, so negative values should literally be impossible… :confused:

Hopefully the change here will fix the issue: Once the tests are completed and I’ve merged that change into the master code branch, please pull the changes, re-compile your binaries, and re-run on the same data to confirm that the issue no longer occurs.

Thanks for all the effort, however, I still didn’t manage to get working results.

As you suggested I adjusted the original command (5tt2gmwmi.ccp) and recompiled the binaries (I assume that running ‘./build’ and resetting the path would suffice).
But that didn’t solve the problem (mrview still displays negative values).
Instead I manually added the line of code in my own script, but that resulted in following error:
> [ERROR] error converting string "gmwmi.nii"

This is the full command I use to create the gmwmi.nii (no other operations on gmwmi.nii happen after this until the tkgen)
> 5tt2gmwmi ${dwi_results}/5tt.nii ${dwi_results}/gmwmi_tmp.nii
> mrtransform ${dwi_results}/gmwmi_tmp.nii -template ${dwi_results}/T1_regis.nii ${dwi_results}/gmwmi.nii
> mrcalc gmwmi.nii 0.0 -max gmwmi_fix.nii

So far I know and understand, there is nothing special about the images I use. Everything looks normal after being processed.

Hope you still have some ideas left. :slightly_smiling:

Ah OK, there’s the problem.

The mrtransform call is re-gridding the GMWMI image, which is calculated in the space of the 5TT image, to the space of some other image. This will be invoking cubic interpolation, which can achieve negative values even if the input image is strictly non-negative. So to do it this way, you’ll have no choice but to run the mrcalc step to guarantee non-negative values.

I would be taking a step further backwards though. If you’re doing the registration after 5ttgen and then re-gridding to the registered T1 image, I would strongly recommend changing your processing order. If you perform registration of T1 to diffusion before running 5ttgen, then the 5TT and T1 images will inherently be in the same space, and there will be no need for mrtransform.


Indeed you’re right.
I switched up my preprocessing order, as suggested and removed the $transform command. It works!

Thanks for the help