Error saving image output

Dear All,

I may be doing something wrong, I am not sure. I am trying to use dwi2mask with the following command line:

/Applications/mrtrix3/release/bin/dwi2mask -info -fslgrad 6.forbedpost/bvecs 6.forbedpost/bvals -force -debug 6.forbedpost/data.nii mrtrix/mrtrix_mask.nii

I am using MRTrix3 in a Macbook Pro.

I am getting this error as output (the last two lines):

dwi2mask: [WARNING] existing output files will be overwritten
dwi2mask: [DEBUG] No config file found at "/etc/mrtrix.conf"
dwi2mask: [DEBUG] No config file found at ".mrtrix.conf"
dwi2mask: [INFO] opening image "6.forbedpost/data.nii"...
dwi2mask: [DEBUG] memory-mapping file "6.forbedpost/data.nii"...
dwi2mask: [DEBUG] file "6.forbedpost/data.nii" mapped at 0x101169000, size 419796352 (read-only)
dwi2mask: [DEBUG] unmapping file "6.forbedpost/data.nii"
dwi2mask: [DEBUG] sanitising image information...
dwi2mask: [DEBUG] memory-mapping file "6.forbedpost/data.nii"...
dwi2mask: [DEBUG] file "6.forbedpost/data.nii" mapped at 0x101169000, size 419796000 (read-only)
dwi2mask: [DEBUG] image "6.forbedpost/data.nii" loaded
dwi2mask: [DEBUG] image "6.forbedpost/data.nii" initialised with strides = [ -1 130 16900 1521000 ], start = 129, using indirect IO
dwi2mask: [DEBUG] initialising threads...
dwi2mask: [DEBUG] launching 8 threads "loop threads"...
dwi2mask: [  0%] preloading data for "6.forbedpost/data.nii"... 
dwi2mask: [DEBUG] waiting for completion of threads "loop threads"...
dwi2mask: [100%] preloading data for "6.forbedpost/data.nii"... 
dwi2mask: [DEBUG] threads "loop threads" completed OK
dwi2mask: [100%] preloading data for "6.forbedpost/data.nii"
dwi2mask: [DEBUG] image "6.forbedpost/data.nii" initialised with strides = [ -138 17940 2332200 1 ], start = 17802, using direct IO
dwi2mask: [DEBUG] searching for suitable gradient encoding...
dwi2mask: [DEBUG] loading matrix file "6.forbedpost/bvals"...
dwi2mask: [DEBUG] found 1x138 matrix in file "6.forbedpost/bvals"
dwi2mask: [DEBUG] loading matrix file "6.forbedpost/bvecs"...
dwi2mask: [DEBUG] found 3x138 matrix in file "6.forbedpost/bvecs"
dwi2mask: [INFO] found 138x4 diffusion gradient table
"...mask: [INFO] creating image "mrtrix/mrtrix_mask
dwi2mask: [DEBUG] sanitising image information...
dwi2mask: [DEBUG] unmapping file "6.forbedpost/data.nii"
dwi2mask: [DEBUG] image "6.forbedpost/data.nii" unloaded
"wi2mask: [ERROR] unknown format for image "mrtrix/mrtrix_mask.nii
"wi2mask: [ERROR] error creating image "mrtrix/mrtrix_mask.nii

Does any one have a clue of what may be going wrong?

I tried to flip the bvecs,bvals vectors and also tried with no bvecs,bvals information at all, but the same error remains.
I tried to change the output format from .nii to .nii.gz or removing it, but it also does not change the error.

Thanks for the help,

best,

João V. Dornas

My best guess here is that the mrtrix/ output folder doesn’t exist yet…? What happens if you run mkdir mrtrix before running your command?

If that’s the problem, we’ll have to see if we can provide a more relevant error message than that…

By the way, are you sure you copy/pasted the terminal output exactly as it was produced…? If so, there may be a dangling non-printing character at the end of your filename. This would most likely be a carriage return (\r), which would cause the cursor to move to the beginning of the line - this would explain why the lines reporting the filename mrtrix/mrtrix_mask.nii start with a "wi2mask:, as the inverted commas are supposed to be at the end of the line…

If that’s the case, the most likely reason for the dangling character is that it came from a copy/paste operation, or you inadvertently pressed some funny key combination…

Also, I’ve just tried to reproduce the above when the output folder doesn’t exists: this is unlikely to be the problem, you would get the correct error in that case:

dwi2mask: [ERROR] error creating output file "mrtrix/mrtrix-mask.nii": No such file or directory
dwi2mask: [ERROR] error creating image "mrtrix/mrtrix-mask.nii"

Thanks for your attention jdtournier.

I corrected this problem with carriage return. The problem is probably because I was using the command inside a csh script.
But it did not solve the problem.

Please take a look on the new terminal output:

ibio226:B0-DTI joaodornas$ /Applications/mrtrix3/release/bin/dwi2mask -info -fslgrad 6.forbedpost/bvecs 6.forbedpost/bvals -force -debug 6.forbedpost/data.nii mrtrix_mask
dwi2mask: [WARNING] existing output files will be overwritten
dwi2mask: [DEBUG] No config file found at "/etc/mrtrix.conf"
dwi2mask: [DEBUG] No config file found at ".mrtrix.conf"
dwi2mask: [INFO] opening image "6.forbedpost/data.nii"...
dwi2mask: [DEBUG] memory-mapping file "6.forbedpost/data.nii"...
dwi2mask: [DEBUG] file "6.forbedpost/data.nii" mapped at 0x1046f7000, size 419796352 (read-only)
dwi2mask: [DEBUG] unmapping file "6.forbedpost/data.nii"
dwi2mask: [DEBUG] sanitising image information...
dwi2mask: [DEBUG] memory-mapping file "6.forbedpost/data.nii"...
dwi2mask: [DEBUG] file "6.forbedpost/data.nii" mapped at 0x1046f7000, size 419796000 (read-only)
dwi2mask: [DEBUG] image "6.forbedpost/data.nii" loaded
dwi2mask: [DEBUG] image "6.forbedpost/data.nii" initialised with strides = [ -1 130 16900 1521000 ], start = 129, using indirect IO
dwi2mask: [DEBUG] initialising threads...
dwi2mask: [DEBUG] launching 8 threads "loop threads"...
dwi2mask: [  0%] preloading data for "6.forbedpost/data.nii"... 
dwi2mask: [DEBUG] waiting for completion of threads "loop threads"...
dwi2mask: [100%] preloading data for "6.forbedpost/data.nii"... 
dwi2mask: [DEBUG] threads "loop threads" completed OK
dwi2mask: [100%] preloading data for "6.forbedpost/data.nii"
dwi2mask: [DEBUG] image "6.forbedpost/data.nii" initialised with strides = [ -138 17940 2332200 1 ], start = 17802, using direct IO
dwi2mask: [DEBUG] searching for suitable gradient encoding...
dwi2mask: [DEBUG] loading matrix file "6.forbedpost/bvals"...
dwi2mask: [DEBUG] found 1x138 matrix in file "6.forbedpost/bvals"
dwi2mask: [DEBUG] loading matrix file "6.forbedpost/bvecs"...
dwi2mask: [DEBUG] found 3x138 matrix in file "6.forbedpost/bvecs"
dwi2mask: [INFO] found 138x4 diffusion gradient table
dwi2mask: [INFO] creating image "mrtrix_mask"...
dwi2mask: [DEBUG] sanitising image information...
dwi2mask: [DEBUG] unmapping file "6.forbedpost/data.nii"
dwi2mask: [DEBUG] image "6.forbedpost/data.nii" unloaded
dwi2mask: [ERROR] unknown format for image "mrtrix_mask"
dwi2mask: [ERROR] error creating image "mrtrix_mask"
ibio226:B0-DTI joaodornas$ 

The path is on a network share, but I have read/write access. I can run FSL commands and do mkdir, rmdir, etc.

Good to hear. That last problem’s easy: your last argument is mrtrix_mask, without a suffix. MRtrix3 relies on the filename extension to determine the output file format… Try adding .nii to that last argument.

Ok! Great! Solved my problem. Thanks a lot. I tried .nii and .nii.gz before but I guess that the first problem with carriage return was preventing to save the data. Thanks for the help!