ROI Mask Question

Dear MRtrix experts,

I am creating an ROI mask and extract FA and MD values within the ROI mask. After creating the ROI mask based on FreeSurfer segmentation, I further created a threshold for CSF volume fraction above 50% using the below scripts.

mrthreshold -force CSF.nii.gz CSF_50.nii.gz -abs 0.5
mrcalc -force CSF_50.nii.gz 0 ROI.nii.gz -if cleaned_ROI.nii.gz

The problem is that the dimension of the ROI mask changed after creating the threshold like below.

Before

Image: “ROI.nii.gz”

Dimensions: 140 x 140 x 84
Voxel size: 1.5 x 1.5 x 1.5
Data strides: [ -1 -2 3 ]
Format: NIfTI-1.1 (GZip compressed)
Data type: 32 bit float (little endian)
Intensity scaling: offset = 0, multiplier = 1
Transform: 1 1e-16 -5.446e-17 -103.3
-1e-16 0.8387 -0.5446 -46.09
-0 0.5446 0.8387 -86.25

After

Image: “cleaned_ROI.nii.gz”

Dimensions: 140 x 140 x 84 x 65
Voxel size: 1.5 x 1.5 x 1.5 x ?
Data strides: [ -1 -2 3 4 ]
Format: NIfTI-1.1 (GZip compressed)
Data type: 32 bit float (little endian)
Intensity scaling: offset = 0, multiplier = 1
Transform: 1 1e-16 -5.446e-17 -103.3
-1e-16 0.8387 -0.5446 -46.09
-0 0.5446 0.8387 -86.25

So when I was using fslstats to extract the values, there was an error message saying “Mask and image must be the same size”. The ROI extraction worked well before thersholding. Could you please advise how to resolve this?

Best,
JW

I expect this means that your CSF.nii.gz input was originally 4D? Can you confirm with mrinfo CSF.nii.gz?

If that’s the case, and you’re only interested in the thresholding the 1st volume, then this should do it:

mrconvert CSF.nii.gz -coord 3 0 - | mrthreshold - CSF_50.nii.gz -abs 0.5
mrcalc -force CSF_50.nii.gz 0 ROI.nii.gz -if cleaned_ROI.nii.gz

Or as a one-liner:

mrconvert CSF.nii.gz -coord 3 0 - | mrthreshold - - -abs 0.5 | mrcalc - 0 ROI.nii.gz -if cleaned_ROI.nii.gz -force

Hi Donald,

Thank you so much! The script you provided worked well. And, yes the CSF file was 4D - below is the mrinfo of the file.


Image: “CSF.nii.gz”


Dimensions: 140 x 140 x 84 x 65
Voxel size: 1.5 x 1.5 x 1.5 x ?
Data strides: [ -1 -2 3 4 ]
Format: NIfTI-1.1 (GZip compressed)
Data type: 32 bit float (little endian)
Intensity scaling: offset = 0, multiplier = 1
Transform: 1 1e-16 -5.446e-17 -103.3
-1e-16 0.8387 -0.5446 -46.09
-0 0.5446 0.8387 -86.25

Best,
JW