Skip to content

Commit

Permalink
-export_grad_fsl: Clamp some b-values to zero
Browse files Browse the repository at this point in the history
Where the gradient direction vector is zero, but the b-value is non-zero, when FSL's "eddy" attempts to rotate the directions of b>0 volumes according to subject rotation, this results in corrupted gradient directions.
This change prevents such data from reaching "eddy" within dwifslpreproc, by detecting volumes where the gradient vector is zero and the b-value is non-zero but is classified by MRtrix3 as non-zero based on BZeroThreshold and forcing the value within the bvals file to be zero.
Relates to #2577.
  • Loading branch information
Lestropie committed Mar 14, 2023
1 parent 260d9c9 commit c845849
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion core/dwi/gradient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@ namespace MR
{
const auto grad = parse_DW_scheme (header);

size_t bval_zeroed_count = 0;

// rotate vectors from scanner space to image space
Eigen::MatrixXd G = grad.leftCols<3>() * header.transform().rotation();

Expand All @@ -191,7 +193,12 @@ namespace MR
bvecs(0,n) = header.stride(order[0]) > 0 ? G(n,order[0]) : -G(n,order[0]);
bvecs(1,n) = header.stride(order[1]) > 0 ? G(n,order[1]) : -G(n,order[1]);
bvecs(2,n) = header.stride(order[2]) > 0 ? G(n,order[2]) : -G(n,order[2]);
bvals(0,n) = grad(n,3);
if (!G.row(n).squaredNorm() && grad(n, 3) <= MR::DWI::bzero_threshold()) {
++bval_zeroed_count;
bvals(0,n) = 0.0;
} else {
bvals(0,n) = grad(n,3);
}
}

// bvecs format actually assumes a LHS coordinate system even if image is
Expand All @@ -200,6 +207,11 @@ namespace MR
if (adjusted_transform.linear().determinant() > 0.0)
bvecs.row(0) = -bvecs.row(0);

if (bval_zeroed_count) {
WARN("For image \"" + header.name() + "\", " + str(bval_zeroed_count) + " volumes had zero gradient direction vector, but 0.0 < b-value <= BZeroThreshold; "
"these are clamped to zero in bvals file \"" + bvals_path + "\" for compatibility with external software");
}

save_matrix (bvecs, bvecs_path, KeyValues(), false);
save_matrix (bvals, bvals_path, KeyValues(), false);
}
Expand Down

0 comments on commit c845849

Please sign in to comment.