Question: combination of warp files and motion correction output?

Hi all,
We try as far as possible to avoid saving our processed fMRI images as new files after each step. My question is whether it is possible to combine the normalisation warp files with the results from sct_fmri_moco (e.g. …moco_x.nii.gz) into a single warp file. Nothing I’ve tried so far has worked.

By the way, the -dl function in sct_fmri_moco works very well! Great work!!

Best
Hanna

1 Like

Hi @Hanna,

Thank you for your question! Just to make sure I’m understanding your needs correctly, what would you be planning to use the combined moco_x.nii.gz+moco_y.nii.gz file for?

For example, are you looking for the complete warping field to be used with e.g. sct_apply_transfo to be able to re-apply the motion correction transformation to another image?

(I ask because SCT has some prototype code for outputting a reusable warping field, and so understanding your use-case will help inform whether this would be helpful or not.)

Kind regards,
Joshua

Hi Joshua,

Yes, that’s exactly what I am trying to do. I tried to combine moco_x.nii.gz, moco_y.nii.gz, and other warp… nii.gz files for use in sct_apply_transfo.

Kind regards,
Hanna

Dear @Hanna,

My deepest apologies for the late reply. I am actively working on a small utility script that will merge the moco params files for you. I will reply shortly once the utility script is complete.

Kind regards,
Joshua

Note: I missed a previous discussion on this topic, which does contain some answers that are more straightforward than the steps I took:

Here is the work I did separately, which more or less arrives at a similar conclusion:

Attached is a script that will generate the merged warping field:

Note, however, that at this time, sct_apply_transfo doesn’t currently support warping fields with different per-volume translations (e.g. [x, y, z, t, 3] where t>1). Currently, sct_apply_transfo will split the input image into multiple volumes, then try to apply the full warping field to each. But, in reality, the warping field should be split too.

To get around this, I needed to split the files per-volume and apply the warping field individually, then re-merge. Something akin to:

# split into individual volumes
sct_image -i warp_moco.nii.gz -split t
sct_image -i fmri.nii.gz -split t
sct_image -i fmri_moco.nii.gz -split t
# sample test using only the first timepoint (T0000)
TIDX=$(printf "T%04d" 0)
WARP_VOL="warp_moco_${TIDX}.nii.gz"
FMRI_VOL="fmri_${TIDX}.nii.gz"
MOCOVOL="fmri_moco_${TIDX}.nii.gz"
OUT_VOL="fmri_moco_from_warp_${TIDX}.nii.gz"
sct_apply_transfo \
    -i "$FMRI_VOL" \
    -d fmri_mean.nii.gz \
    -w "$WARP_VOL" \
    -o "$OUT_VOL" \
    -x linear

Note, though, that re-merging the warped volumes will likely be quite memory-intensive.


All this is to say: This is not something we formally support yet, and it will require some changes on our part, but this is something we have wanted to support for some time:

Thank you again for your patience and understanding,
Joshua