Hello NeuroStars Community,
I am testing out CaPTk https://cbica.github.io/CaPTk/index.html as a means for automatic lesion segmentation in a collection of MRIs from a brain tumor database. In CaPTk, you input 4 structural MRIs (i.e., T1CE, T1, T2, and FLAIR) and it will output a segmented lesion. It is working well but I need a way to convert the lesion segmentation back into the subject’s native space (in this case, the contrast enhanced T1 [or T1CE].
The basic preprocessing steps implemented by CaPTk relevant for this question include orientation to RAI space (input data was initially in LPI) and transformation to SRI standard space. The segmented lesion output is in this standard SRI space with RAI orientation. The developers of CaPTk were nice enough to include a T1CE_nativespace-to-SRI transformation matrix in their output so I thought it was going to be easy to just apply the inverse of that transformation matrix to the lesion and flip back to LPI. However, nothing I have tried has worked.
The command below got me close but it only worked when the transformation matrix (-t) was not inverted ( T1CE_to_SRI.txt, 0 instead of T1CE_to_SRI.txt, 1) and the z direction was still way off.
antsApplyTransforms -d 3 -i Segm.nii.gz -r T1CE_raw.nii.gz -o Segm_transformed.nii -t [T1CE_to_SRI.txt, 0] -n NearestNeighbor
Below is some selected header output from fslhd for the different nifti files in question as well as the different transformation files.
T1CE_raw.nii (this is the original native space)
qto_xyz:1 0.464286 0 0 -125.573822
qto_xyz:2 0 0.464286 0 -106.271393
qto_xyz:3 0 0 1 -65.752281
qto_xyz:4 0 0 0 1
dim1 560
dim2 560
dim3 180
pixdim0 1
pixdim1 0.464286
pixdim2 0.464286
pixdim3 1
T1CE_RAI.nii (this is the first output of the preprocessing after reorienting to RAI; seems unusual that the fourth column has changed and im wondering if this this perhaps the issue)
qto_xyz:1 -0.464286 0 0 133.961884
qto_xyz:2 0 -0.464286 0 153.264313
qto_xyz:3 0 0 1 -65.752281
qto_xyz:4 0 0 0 1
dim1 560
dim2 560
dim3 180
pixdim0 1
pixdim1 0.464286
pixdim2 0.464286
pixdim3 1
T1CE_RAI_SRI.nii (this is the one that was transformed to SRI space via linear transformation)
qto_xyz:1 -1 0 0 0
qto_xyz:2 0 -1 0 239
qto_xyz:3 0 0 1 0
qto_xyz:4 0 0 0 1
dim1 240
dim2 240
dim3 155
pixdim0 1
pixdim1 1
pixdim2 1
pixdim3 1
Segm.nii (this is the segmented lesion output)
qto_xyz:1 -1 0 0 0
qto_xyz:2 0 -1 0 239
qto_xyz:3 0 0 1 0
qto_xyz:4 0 0 0 1
dim1 240
dim2 240
dim3 155
pixdim0 1
pixdim1 1
pixdim2 1
pixdim3 1
Transformation Files
From CaPTk, there was a T1CE_raw_to_SRI .mat file that I converted to text. It was a simple 4x4 array.
0.9991 -0.0215 0.0368 123.9250
0.0182 0.9961 0.0858 -96.2847
-0.0385 -0.0850 0.9956 -42.3663
0 0 0 1
I modified the matrix above to conform to antsApplyTransforms formatting:
#Insight Transform File V1.0
#Transform 0
Transform: AffineTransform_double_3_3
Parameters: 0.999089 -0.0215002 0.0368544 0.0182706 0.996142 0.0858323 -0.0385576 -0.0850807 0.995628 123.925 -96.2847 -42.3663
FixedParameters: 0 0 0
After running the antsApplyTransforms command above on the segmented lesion, the output (Segm_transformed.nii) fslhd is:
qto_xyz:1 0.464286 0 0 -125.573822
qto_xyz:2 0 0.464286 0 -106.271393
qto_xyz:3 0 0 1 -65.752281
qto_xyz:4 0 0 0 1
dim1 560
dim2 560
dim3 180
pixdim0 1
pixdim1 0.464286
pixdim2 0.464286
pixdim3 1
When I look at this Segm_transformed.nii in MRIcron as an overlay on top of the original T1CE_raw.nii, the lesion is far too superior on z axis (such that flipping the z translation in the matrix from -42.3663 to 42.3663 almost makes it perfect).
It seems strange that the Segm_transformed.nii is misaligned in the z direction and not the x or y direction given that I never re-oriented the image back to LPI space.
If there is anyone that can provide me some direction on this, I would be very grateful!
Cheers,
Travis