Skip to content

Commit 30c24e3

Browse files
authored
Merge pull request #1714 from MRtrix3/dwi2mask_fslgrad_fix
dwi2mask: Fix segfault with -fslgrad
2 parents 1b818fc + ff11902 commit 30c24e3

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/dwi/gradient.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,9 @@ namespace MR
117117
if (bvals.cols() != bvecs.cols())
118118
throw Exception ("bvecs and bvals files must have same number of diffusion directions (file \"" + bvecs_path + "\" has " + str(bvecs.cols()) + ", file \"" + bvals_path + "\" has " + str(bvals.cols()) + ")");
119119

120-
if (bvals.cols() != header.size (3))
121-
throw Exception ("bvecs and bvals files must have same number of diffusion directions as DW-image (gradients: " + str(bvecs.cols()) + ", image: " + str(header.size(3)) + ")");
120+
const size_t num_volumes = header.ndim() < 4 ? 1 : header.size(3);
121+
if (size_t(bvals.cols()) != num_volumes)
122+
throw Exception ("bvecs and bvals files must have same number of diffusion directions as DW-image (gradients: " + str(bvecs.cols()) + ", image: " + str(num_volumes) + ")");
122123

123124
// bvecs format actually assumes a LHS coordinate system even if image is
124125
// stored using RHS - x axis is flipped to make linear 3x3 part of

0 commit comments

Comments
 (0)