Use of different data types

Hello MRtrix experts,

I am relatively new to this forum. I have been working with your documentation site and community forum, but there is a couple of questions I didn’t really find the answers to. Any advice will be greatly helpful!

I’m preprocessing my dti data with mrtrix3. First I convert .nii file to .mif file and change datatype int16 to float32 at the same time. A slightly simplified command is as follows:

# dicom to nifti
    dcm2niix -f dwi dicomdir
    dcm2niix -f dwi_PA PAdicomdir (# This is only for topup) 

# nii to mif
    mrconvert dwi.nii dwi.mif -fslgrad dwi.bvec dwi.bval -datatype float32

# denoise and degibbs
    dwidenoise dwi.mif dwi_den.mif -noise dwi_noise.mif
    mrdegibbs dwi_den.mif dwi_den_unr.mif -axes 0,1

# making b0_pair for topup
    dwiextract dwi_den_unr.mif - -bzero | mrmath - mean mean_b0_AP.mif -axis 3
    mrconvert dwi_PA.nii temp01.mif -fslgrad dwi_PA.bvec dwi_PA.bval -datatype float32
    dwiextract temp01.mif - -bzero | mrmath - mean mean_b0_PA.mif -axis 3
    mrcat mean_b0_AP.mif mean_b0_PA.mif -axis 3 b0_pair.mif
    rm temp01.mif

# getting TotalReadoutTime from json file
TotalReadoutTime=`cat dwi.json | grep TotalReadoutTime | cut -d: -f2 | tr -d ','`

# dwifslpreproc topup & eddy
    dwifslpreproc dwi_den_unr.mif dwi_den_unr_preproc.mif -pe_dir AP -rpe_pair -se_epi b0_pair.mif -eddy_options " --slm=linear" -readout_time $TotalReadoutTime

# correct b1 field bias
    dwibiascorrect ants dwi_den_unr_preproc.mif dwi_den_unr_preproc_unbiased.mif -bias bias.mif

# make mask for dtifit and convert to nifti 
    dwi2mask dwi_den_unr_preproc_unbiased.mif mask_den_unr_preproc_unb.nii.gz
    mrconvert dwi_den_unr_preproc_unbiased.mif dwi_den_unr_preproc_unbiased.nii.gz -export_grad_fsl new.bvec new.bval

Now I want try rpg-degibbs instead of mrdegibbs because my data is partial Fourier acquisition, and this pipeline seems to require datatype int.
My first question is when is the best timing to convert the data type to float32. I want to do the denoise first, but do I need to convert datatype to float32 before denoise? If not, I would like to do denoise as int16 and convert to float32 after rpg-degibbs is done.
And my second question is if it is necessary to do denoise and degibbs for PA data, because I use them only for distortion correction with topup.

Thank you very much for your help!

You can input int32-data in dwidenoise, but its output will always be in floating point. The reason is that the trunctated singular value decomposition in MP-PCA has to be evaluated in floating point. You can round the output to the nearest integer if you wish, but that will introduce quantization noise so I would advise against it.

Are you sure that rpg-degibbs requires integer input? I have not tested it, but I don’t see anything in the paper that could not also work in floating point.

Denoising the reverse phase encoding (RPE) data is not possible if the protocol includes only a few b=0 volumes with RPE. You can degibbs them though. I would then treat the corresponding b=0 volumes of the forward PE data in the same way (only for the b=0 pair!).

As a side note, I notice your script uses the mean AP and mean PA b=0 images for the b=0 pair. I would advise against this, as the mean could be affected by motion. You can just use all b=0 images instead, or select one or two from each if using all takes too long. Topup includes a rigid registration that will correct subject motion.

1 Like

Hi Daan,

Thank you very much for your help!

Thanks for very helpful advice. I understand that the result of the calculation will be a float. So it would be better if I could input the float to rpg-degibbs. The last time I tried it, I got an error when I entered int16, but I will look into it to see if there is another way.
Here is a new question, the data after conversion by dcm2niix is int16 instead of int32. is there any difference between the two as input for dwidenoise? To pursue this further, what is the best type of input image?

If I understand correctly, you mean instead of doing denoise and degibbs and then extracting the b0s, I would first extract the b0 pair (in the reversed phase directions) and then only do degibbs on these? That sounds a good idea. I will try it!

As far as visually checking my average b0 pair image, the effect of the motion is not clear, but if topup will register it, it would be better not to average it as you say.

Thanks again for your time and helpful advices!

Dicom conversion preserves the data type and precision of the input DCM images. It does not really matter what data type you input to dwidenoise, internally it will always be converted to single or double floats.

Yes, that is what I meant.

Hi Daan,

Following your advice, I tried again to input float32 to rpg-degibbs and it worked this time. I looked in the manual and there is no ’float32’ in the datatype but there is ’single’…that’s what matlab calls it… I learned a lot :sweat_smile:

Thnaks again for your kind help!