diff --git a/src/dwi/gradient.cpp b/src/dwi/gradient.cpp index f333ea8e90..826e99d6eb 100644 --- a/src/dwi/gradient.cpp +++ b/src/dwi/gradient.cpp @@ -117,8 +117,9 @@ namespace MR if (bvals.cols() != bvecs.cols()) 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()) + ")"); - if (bvals.cols() != header.size (3)) - 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)) + ")"); + const size_t num_volumes = header.ndim() < 4 ? 1 : header.size(3); + if (size_t(bvals.cols()) != num_volumes) + throw Exception ("bvecs and bvals files must have same number of diffusion directions as DW-image (gradients: " + str(bvecs.cols()) + ", image: " + str(num_volumes) + ")"); // bvecs format actually assumes a LHS coordinate system even if image is // stored using RHS - x axis is flipped to make linear 3x3 part of