beauchamplab / raveio

File IO for RAVE Project
6 stars 2 forks source link

ACPC realignment with ANTs creates misaligned results #20

Open dipterix opened 1 month ago

dipterix commented 1 month ago

Quote from Slack channel:

I found something strange. So I did again the same patient that we walked through together, after freesurfer recon and co-regist (both with MRI_ACPC), I plotted the overlay between MRI_reference and CT_in_t1 in ITK-snap and looked like quite aligned. However, when I proceed with elec loc, in RAVE viewer the CT looks like a bit off, a bit shifted to the side like what we saw yesterday if you remember, I wonder if it's possible... as in ITK it looks like very well aligned...

This is because after ACPC realignment, the MRI_acpc will have two matrices in the header see Method 2: qform and Method 3: sform in NIfTI header specification

The imaging file MRI_acpc has qform remain unchanged as it should be voxel to original T1w RAS transformation. sform is set to be voxel to ACPC realigned RAS.

What happened was Freesurfer uses sform for reconstruction, and ANTs used qform for coregistration.

In FreeSurfer mailing archive, https://www.mail-archive.com/freesurfer@nmr.mgh.harvard.edu/msg02870.html it states that when sform is valid, then fs recon-all prioritize sform.

For ANTs, it uses ITK as low-level engine according to this issue: https://github.com/ANTsX/ANTsPy/issues/434, and according to ITK mailing list https://itk.org/pipermail/insight-users/2017-March/054354.html, ITK was clearly using qform only. This is also consistent with my observation.

This is annoying as nifti specs doesn't seem to prioritize the s/q forms when they are inconsistent. SPM, FSL, FreeSurfer put sform > qform, while ANTs, ITK, ITKSnap all used qform only.

dipterix commented 1 month ago

For immediate solution: align CT to T1.nii.gz. The CT will be aligned to FreeSurfer-generated T1 image. This image has consistent s/qform, which is identical to sform of the ACPC realigned image.

dipterix commented 1 month ago

Pipeline has been updated to force ACPC to have consistent s/qform. We might want to consider a better solution in the future once RAVE finishes up converting to native BIDS compliant.

https://github.com/rave-ieeg/rave-pipelines/commit/1f22ddf73ca77fec7a9c629e69c83778086acb03

A follow-up issue has been posted at https://github.com/ANTsX/ANTsPy/issues/356

dipterix commented 1 month ago

It turns out if the input MRI has already been preprocessed with inconsistent s/qforms, then the pipeline will almost surely fail. Perhaps when importing images, the pipeline should automatically fix this inconsistency.