---
# System prepended metadata

title: XFMS workflow detailed

---

# XFMS workflow detailed

**T2-to-T1 registration**
*Register cropped T2 to cropped T1*
out: T2w_registered_to_T1w.nii.gz and cropT2tocropT1.mat
`flirt -ref cropped/T1w/sub-*_0000.nii.gz -in cropped/T2w/sub-*_0001.nii.gz -omat resized/xfms/cropT2tocropT1.mat -out resized/xfms/T2w_registered_to_T1w.nii.gz -cost mutualinfo -searchrx -15 15 -searchry -15 15 -searchrz -15 15 -dof 6`

**Apply identity matrix to T1 and T2 to resize**
*Apply identity matrix to cropped T1*
out: T1w_to_BIBS.nii.gz and crop_T1w_to_BIBS_template.mat
`flirt -in cropped/T1w/sub-*_0000.nii.gz -ref templates/INFANT_MNI_T1_1mm.nii.gz -applyisoxfm 1 -init /home/cabinet/data/identity_matrix.mat -o resized/xfms/T1w_to_BIBS.nii.gz -omat resized/xfms/crop_T1w_to_BIBS_template.mat`

*Apply identity matrix to T1-registered cropped T2*
out: T2w_to_BIBS.nii.gz and crop_T2w_to_BIBS_template.mat
`flirt -in resized/xfms/T2w_registered_to_T1w.nii.gz -ref templates/INFANT_MNI_T2_1mm.nii.gz -applyisoxfm 1 -init /home/cabinet/data/identity_matrix.mat -o resized/xfms/T2w_to_BIBS.nii.gz -omat resized/xfms/crop_T2w_to_BIBS_template.mat`

**Create full2cropT{1/2}w.mat from T{1/2}w_full2crop.mat and identity matrix for both T1 and T2**
*Take inverse of crop2full.mat*
`convert_xfm -inverse cropped/T{1/2}w/crop2full.mat -omat resized/ACPC_align/T{1/2}w_full2crop.mat`

*Concatenate full2crop with identity matrix*
`convert_xfm -omat resized/xfms/full2cropT{1/2}w.mat -concat resized/ACPC_align/T{1/2}w_full2crop.mat /home/cabinet/data/identity_matrix.mat`

**Concatenate matrices and apply to average T1/T2 to result in output files with correct size and resolution**
*T1w: concatenate full2cropT1w.mat and crop_T1w_to_BIBS_template.mat to make full_crop_T1w_to_BIBS_template.mat*
`convert_xfm -omat resized/xfms/full_crop_T1w_to_BIBS_template.mat -concat resized/xfms/full2cropT1w.mat resized/xfms/crop_T1w_to_BIBS_template.mat`

*T1w: apply full_crop_T1w_to_BIBS_template.mat to average T1 to make preBIBSnet_final_0000.nii.gz*
`applywarp --rel --interp=spline -i averaged/sub-5002_ses-SE_0000.nii.gz -r templates/INFANT_MNI_T1_1mm.nii.gz --premat=resized/xfms/full_crop_T1w_to_BIBS_template.mat -o resized/xfms/preBIBSnet_final_0000.nii.gz`

*T2w: concatenate full2cropT2.mat and cropT2tocropT1.mat to create intermediate full2cropT2toT1.mat that captures cropping and T2-T1 registration*
`convert_xfm -omat resized/xfms/full2cropT2toT1.mat -concat resized/xfms/cropT2tocropT1.mat resized/xfms/full2cropT2w.mat`

*T2w: concatenate intermediate full2cropT2toT1.mat and crop_T2w_to_BIBS_template.mat to make full_crop_T2w_to_BIBS_template.mat*
`convert_xfm -omat resized/xfms/full_crop_T2w_to_BIBS_template.mat -concat resized/xfms/crop_T2w_to_BIBS_template.mat resized/xfms/full2cropT2toT1.mat`

*T2w: apply full_crop_T2w_to_BIBS_template.mat to average T2 to get preBIBSnet_final_0001.nii.gz*
`applywarp --rel --interp=spline -i averaged/sub-5002_ses-SE_0001.nii.gz -r templates/INFANT_MNI_T2_1mm.nii.gz --premat=resized/xfms/full_crop_T2w_to_BIBS_template.mat -o resized/xfms/preBIBSnet_final_0001.nii.gz`