`flirt` from BIDS T1w to QSIPREP T1w not working

flirt from BIDS T1w to QSIPREP T1w is not working.

Hello, because the default skull stripping method used in QSIPREP is not adequate for our infant data, we decided to swap the qsiprep’s anatomical brain mask (which is later used during qsiprep reconstruction) with the brain mask obtained from another pipeline that more accurately does skull stripping.

However, as the picture below shows, we found that the Red (BIDS T1w) image is not aligned with the Grey (QSIPREP T1w) image. (orange is the skull stripped image)

We tried running flirt

flirt -in BIDS/sub-150758/anat/sub-150758_T1w.nii.gz -ref QSIPREP/sub-150758/anat/sub-150758_desc-preproc_T1w.nii.gz -omat bidst12qsiprept1.mat -out bidst12qsiprept1.nii.gz 

However, the result was like below (red : flirt transformed image from BIDS to QSIPREP, grey : QSIPREP T1w), where the brain image was kind of rotated


(we tired different --dof options, and all gave similar results)

Is there a matrix that I can use to transform from the native space to the T1w space used in QSIPREP?

====
For reference, here are information about the images used

Thank you in advance for anyone’s help!

Hi @Kore_ana,

The anatomical workflow is being updated in the upcoming release, please retry then. In addition, the native-to-ACPC transform will be output in the new version as well. Currently this can be found in your working directory: /work/qsiprep_wf/single_subject_XX_wf/dwi_preproc_wf/b0_anat_coreg/itk_to_rigid/

Best,
Steven

1 Like

Thank you!
I have a few questions :

  1. when is the next version expected to release?
  2. unfortunately, i deleted the /tmp file, which is where I believe your reference is. Is there another way to obtain this?
  3. As my picture in the original question shows, when I manually did flirt from the original image to the qsiprep image, it didn’t work. Is there a way for me to at least to flirt manually?

Thank you again for your response!

Unsure, but hopefully within the next couple of weeks?

Unfortunately no.

I think most of the QSIPrep registrations use ANTs. Can you try to run ANTs registration between your orig and QSIPrep-derived T1?

Thank you! I’ll be on the look out for the new release!

Which ANTs option should I use? I assume I need to use “rigid” option?

Yes, rigid (6 degrees of freedom) should be good since the T1 is only rotated/translated to get to ACPC alignment, no need for scaling or shearing.

1 Like

@Steven Thank you for your comment! I tried as you said, but it till seems that the alignment is still inaccurate.

The code I used was the following :

##1. read images (https://antspy.readthedocs.io/en/latest/core.html#ants.image_read)
bids_img = ants.image_read(filename = './BIDS/sub-150758/anat/sub-150758_T1w.nii.gz')
qsi_img = ants.image_read(filename = './QSIPREP/sub-150758/anat/sub-150758_desc-preproc_T1w.nii.gz')

##2. Do Registration
move_matrix = ants.registration(fixed = qsi_img, moving = bids_img,
                 type_of_transform = "Rigid")
print(move_matrix)

##3. Apply the transform
warped_image = ants.apply_transforms(fixed = qsi_img, moving = bids_img,
                     transformlist = move_matrix['fwdtransforms'])

The move_matrix was :

{'warpedmovout': ANTsImage (RAI)
	 Pixel Type : float (float32)
	 Components : 1
	 Dimensions : (193, 229, 193)
	 Spacing    : (1.0, 1.0, 1.0)
	 Origin     : (-96.0, -96.0, -78.0)
	 Direction  : [1. 0. 0. 0. 1. 0. 0. 0. 1.]
, 'warpedfixout': ANTsImage (LPI)
	 Pixel Type : float (float32)
	 Components : 1
	 Dimensions : (512, 512, 120)
	 Spacing    : (0.4297, 0.4297, 1.0)
	 Origin     : (113.4008, 83.5237, -40.7669)
	 Direction  : [-1.      0.      0.0038  0.     -1.      0.      0.0038  0.      1.    ]
, 'fwdtransforms': ['/var/folders/m3/y3bh88f92_5d37clpvn8jg_00000gn/T/tmp396c97zl0GenericAffine.mat'], 'invtransforms': ['/var/folders/m3/y3bh88f92_5d37clpvn8jg_00000gn/T/tmp396c97zl0GenericAffine.mat']}

and when plotting the resulting images, I found them to be not aligned

(Does the different voxel dimensions have an affect here? Do you think I should resize the BIDS image to 1x1x1 mm then do registration?)

*addition : it seems that the original BIDS image has a total dimension of 220x220x120 mm, while the QSIPREP image has the shape of 193x229x193, which is weird since the original BIDS image has two long edges and one short edge, while the QSIPREP seems to have two short ones and long one edge. Could this be the reason for the error?

I just read that your data comes from infant, did you use the --infant flag?

Thank you for your response, and no we did not

the exact code run was the following, :

docker run --rm  -v /home/connectome/lsy0174/license.txt:/opt/freesurfer/license.txt:ro -v ${data_path}:/data:ro -v ${sub_save_dir}:/out pennbbl/qsiprep:0.16.1 /data /out participant --recon-spec dsi_studio_gqi --output_resolution 1.5 --skip_bids_validation --unringing_method mrdegibbs --omp-nthreads 4

Please retry with the --infant flag and let us know if that improves anything!

in your ants registration do you have a center of mass alignment? That step helps make sure that the images are initially aligned

@Steven Thank you for the suggestion. Unfortunately, it does not seem to work well :

@mattcieslak Thank you for the reply! How will I do the center of mass alignment? Should I use this : Registration — ANTsPy master documentation ? If so, how should I use it?

Also, is the image size (mm) not being same between the two images OK?

the different voxel sizes are no problem. I’m not sure how to do it in antsPy, but with antsRegistration the argument would be --initial-moving-transform 1

If possible, please try out version 0.19.0, which has vastly improved skull stripping for infants