dwi2mask implementation uses a combination of DWI data across all b-values, including b=0; but because the resulting mask is an intersection of masks across b-values, if the mask estimated from the b=0 data (based on an optimal threshold derived from & applied to the mean b=0 image) extends too far, then the final output mask will extend too far. This particular algorithm further does not have any “free parameters” that would be capable of “tuning” the behaviour in this instance.
You would likely be better-served making use of the
dwifslpreproc -eddy_mask option, which will bypass the internal
dwi2mask call by using the image you provide instead. It might not be perfect because ideally the mask utilised by
eddy should contain brain voxels in the undistorted image, so if an image possessing susceptibility distortions is used to produce that mask it may not be quite right; but
eddy is also not super sensitive to the mask, so if the distortions aren’t absurdly large it should be OK.
I’ll also note that in
3.1.0 not only will there be multiple
dwi2mask algorithms to choose from (since it’s a persistent cause of grief, but different approaches work better or worse for different data), it will be possible to specify one’s preferred algorithm in the config file, and that’s the algorithm that will be used whenever an MRtrix3 Python script needs to invoke
dwi2mask internally. You can see a preview of those coming features here.