I have fMRI cervical spinal cord data, and I’d like to concatenate all warping fields produced in my pipeline to apply them all at once :
- motion correction parameters for each run,
- FNIRT inter-run realignment,
- functional to anatomical space transformation, and
- anatomical to template space transformation.
For the 3 last warping fields, I’ve managed to do this with sct_apply_transfo.
Sct_fmri_moco outputs 2 4D nifti files, moco_params_x.nii.gz and moco_params_y.nii.gz (dim1=1, dim2=1, dim3=nb of slices and dim4=nb of scans).
Is there a way to convert these into a warping field that i can also use in sct_apply_transfo ?
Thank you for reaching out. Currently there is no “easy” way to get the transformation files output by
sct_fmri_moco to be used as ITK-compatible transformation files (ie: that could be readily used by
sct_apply_transfo). This has been a feature request for a few years already, but due to a lack of priority this has never been implemented yet.
In principle, it shouldn’t be too difficult to implement this feature. You are welcome to give it a try if you have the bandwidth, and we will happily assist you in the process
Thanks for your quick answer. It was indeed quite straightforward as the warping fields were actually already saved in the temporary folder produced by moco.py.
We tweaked a few lines of the tmp_create function in /utils/fs.py script, to define where the temporary folder should be kept, in order to easily access its content.
“”“Create temporary folder and return its path
prefix = “/home/raphaelle/Documents/CervicalSpine/derivatives/pipeline_dec22/preprocessing/”
prefix += “%s” % basename
tmpdir = prefix
os.makedirs(tmpdir, exist_ok=True) #allows overwrite of tmp folder
logger.info(“Creating temporary folder (%s)” % tmpdir)
Here the temporary folder is thus saved as : “/home/raphaelle/Documents/CervicalSpine/derivatives/pipeline_dec22/preprocessing/moco/”, since the basename variable is defined as ‘moco’ in the moco.py script.
We then copied each warping field file (ex. for 1st volume : /moco/mat_final/mat.Z0000T0000Warp.nii.gz) and its corresponding single volume file (/moco/data_T0000.nii.gz) into a permanent folder, and ran a loop to apply this warping field and others (FNIRT, func->T2 and T2->PAM50 transformations) simultaneously to each volume with sct_apply_transfo using only one interpolation step.
By using the fslmerge function, we then concatenated single-volume warped outputs into a final func image file.
Thanks for the great tool that SCT is !
Just as a side note, thank you for your clear and descriptive feedback about temporary directories! SCT has an open issue about temporary directory usage, and your description here is very informative about how temporary directories like this are used in practice.
Thank you so much for taking the time to describe this working solution, @raphaschl.