Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

antsApplyTransforms not able to read transform txt #1681

Closed
butellyn opened this issue Feb 22, 2024 · 7 comments
Closed

antsApplyTransforms not able to read transform txt #1681

butellyn opened this issue Feb 22, 2024 · 7 comments

Comments

@butellyn
Copy link

Describe the problem

I am trying to use antsApplyTransforms to move a functional image in fmriprep's T1w space into fsnative (freesurfer's T1w space), but the output is not being created. With the "verbose" option turned on, I got a message that the transform file cannot be read. The file was created using fMRIPrep v23.1.4. I am thinking maybe the version of ANTs on my cluster (which seems to be from 2020) may be too old to be compatible with the outputs from fMRIPrep. Does that seem likely to be the case? If not, what might the issue be?

To Reproduce

I ran this command (which took ~30 seconds):

antsApplyTransforms -d 4 -v 1 \
    -i /projects/b1108/studies/mwmh/data/processed/neuroimaging/fmriprep_23.1.4/sub-MWMH212/ses-2/func/sub-MWMH212_ses-2_task-rest_space-T1w_desc-preproc_bold.nii.gz \
    -r /projects/b1108/studies/mwmh/data/processed/neuroimaging/surf/sub-MWMH212/ses-2/anat/fs_T1w.nii.gz \
    -t /projects/b1108/studies/mwmh/data/processed/neuroimaging/fmriprep_23.1.4/sub-MWMH212/ses-2/anat/sub-MWMH212_ses-2_from-T1w_to-fsnative_mode-image_xfm.txt \
    -o /projects/b1108/studies/mwmh/data/processed/neuroimaging/surf/sub-MWMH212/ses-2/func/sub-MWMH212_ses-2_task-rest_space-fsnative_desc-preproc_bold.nii.gz

It returned no output:
Screenshot 2024-02-22 at 3 49 19 PM

And said that it could not read the initial transform:
Screenshot 2024-02-22 at 3 59 20 PM

But the file exists, and is output from fMRIPrep v23.1.4:
Screenshot 2024-02-22 at 4 00 11 PM

Do you know what might cause ANTs to not be able to read in the transformation file? Is it possible that the ANTs version installed on my cluster is too old?

System information (please complete the following information)

  • OS: NAME="Red Hat Enterprise Linux Server"
    VERSION="7.9 (Maipo)"
    ID="rhel"
    ID_LIKE="fedora"
    VARIANT="Server"
    VARIANT_ID="server"
    VERSION_ID="7.9"
    PRETTY_NAME="Red Hat Enterprise Linux Server 7.9 (Maipo)"
    ANSI_COLOR="0;31"
    CPE_NAME="cpe:/o:redhat:enterprise_linux:7.9:GA:server"
    HOME_URL="https://www.redhat.com/"
    BUG_REPORT_URL="https://bugzilla.redhat.com/"

REDHAT_BUGZILLA_PRODUCT="Red Hat Enterprise Linux 7"
REDHAT_BUGZILLA_PRODUCT_VERSION=7.9
REDHAT_SUPPORT_PRODUCT="Red Hat Enterprise Linux"
REDHAT_SUPPORT_PRODUCT_VERSION="7.9"

  • Type of system: HPC cluster
  • CPU architecture: unsure

ANTs version information

  • ANTs code version: ANTs Version: 0.0.0.0 Compiled: Oct 6 2020 04:58:02
  • ANTs installation type: Unsure. Installed by admins

Additional information

Here are details on each of the files:

sub-MWMH212_ses-2_task-rest_space-T1w_desc-preproc_bold.nii.gz:

Spacing [2, 2, 2, 0.555]
Origin [65.6448, 63.687, -59.6174, 0]
Direction
-1 0 0 0
0 -1 0 0
0 0 1 0
0 0 0 1

Size : [69, 90, 69, 1110]

Image Dimensions : [69, 90, 69, 1110]
Bounding Box : {[65.6448 63.687 -59.6174 0], [203.645 243.687 78.3826 616.05]}
Voxel Spacing : [2, 2, 2, 0.555]
Intensity Range : [0, 31125.8]
Mean Intensity : 3874.74
Direction Cos Mtx. :
-1 0 0 0
0 -1 0 0
0 0 1 0
0 0 0 1

Voxel->RAS x-form :
Image Metadata:
ITK_FileNotes = xform matrices modified by FixHeaderApplyTransforms (niworkflows v1.8.1).
ITK_original_direction of unsupported type N3itk6MatrixIdLj4ELj4EEE
ITK_original_spacing of unsupported type St6vectorIdSaIdEE
bitpix = 32
cal_max = 31125.8
cal_min = 0
datatype = 16
descrip = xform matrices modified by FixHeaderApplyTransforms (niworkflows v1.8.1).
dim[0] = 4
dim[1] = 69
dim[2] = 90
dim[3] = 69
dim[4] = 1110
dim[5] = 1
dim[6] = 1
dim[7] = 1
dim_info = 0
intent_code = 0
intent_p1 = 0
intent_p2 = 0
intent_p3 = 0
nifti_type = 1
pixdim[0] = 0
pixdim[1] = 2
pixdim[2] = 2
pixdim[3] = 2
pixdim[4] = 0.555
pixdim[5] = 1
pixdim[6] = 1
pixdim[7] = 1
qform_code = 2
qform_code_name = NIFTI_XFORM_ALIGNED_ANAT
qoffset_x = -65.6448
qoffset_y = -63.687
qoffset_z = -59.6174
quatern_b = 0
quatern_c = 0
quatern_d = 0
scl_inter = 0
scl_slope = 1
sform_code = 2
sform_code_name = NIFTI_XFORM_ALIGNED_ANAT
slice_code = 0
slice_duration = 0
slice_end = 0
slice_start = 0
srow_x = 2 0 0 -65.6448
srow_y = 0 2 0 -63.687
srow_z = 0 0 2 -59.6174
toffset = 0
vox_offset = 352
xyzt_units = 10

fs_T1w.nii.gz (the freesurfer T1w image converted to nifti format):
Spacing [0.8, 0.8, 0.8]
Origin [-132.592, 92.2279, 114.454]
Direction
1 -1.16415e-09 5.82077e-10
5.82077e-10 -0 -1
0 -1 0

Size : 320 320 320

Image Dimensions : [320, 320, 320]
Bounding Box : {[-132.592 92.2279 114.454], [123.408 348.228 370.454]}
Voxel Spacing : [0.8, 0.8, 0.8]
Intensity Range : [0, 182]
Mean Intensity : 11.0504
Direction Cos Mtx. :
1 -1.16415e-09 5.82077e-10
5.82077e-10 -0 -1
0 -1 0

Voxel->RAS x-form :
Image Metadata:
ITK_FileNotes = FreeSurfer Aug 4 2022
ITK_original_direction of unsupported type N3itk6MatrixIdLj3ELj3EEE
ITK_original_spacing of unsupported type St6vectorIdSaIdEE
bitpix = 8
cal_max = 0
cal_min = 0
datatype = 2
descrip = FreeSurfer Aug 4 2022
dim[0] = 3
dim[1] = 320
dim[2] = 320
dim[3] = 320
dim[4] = 1
dim[5] = 1
dim[6] = 1
dim[7] = 1
dim_info = 0
intent_code = 0
intent_p1 = 0
intent_p2 = 0
intent_p3 = 0
nifti_type = 1
pixdim[0] = 0
pixdim[1] = 0.8
pixdim[2] = 0.8
pixdim[3] = 0.8
pixdim[4] = 0
pixdim[5] = 1
pixdim[6] = 1
pixdim[7] = 1
qform_code = 1
qform_code_name = NIFTI_XFORM_SCANNER_ANAT
qoffset_x = 132.592
qoffset_y = -92.2279
qoffset_z = 114.454
quatern_b = 2.05795e-10
quatern_c = 0.707107
quatern_d = -0.707107
scl_inter = 0
scl_slope = 0
sform_code = 1
sform_code_name = NIFTI_XFORM_SCANNER_ANAT
slice_code = 0
slice_duration = 0
slice_end = 0
slice_start = 0
srow_x = -0.8 9.31323e-10 -4.65661e-10 132.592
srow_y = -4.65661e-10 0 0.8 -92.2279
srow_z = 0 -0.8 0 114.454
toffset = 0
vox_offset = 352
xyzt_units = 10

sub-MWMH212_ses-2_from-T1w_to-fsnative_mode-image_xfm.txt:
#Insight Transform File V1.0
#Transform 0
Transform: AffineTransform_float_3_3
Parameters: 1 -0.000130966 -0.000102833 0.000130979 1 0.000149429 0.000102816 -0.000149459 1 -0.000366211 0.0224457 -0.0718994
FixedParameters: 0 0 0

@cookpa
Copy link
Member

cookpa commented Feb 22, 2024

It might be a problem of dimensionality, the correct way to do this is to call

antsApplyTransforms -d 3 -e 3

This tells ANTs to apply the 3D transform to each 3D volume of the bold image. If you call antsApplyTransforms -d 4, it expects 4D transforms (ie, a time-varying transform).

@butellyn
Copy link
Author

Ah! That is very helpful. I tried running this:

antsApplyTransforms -d 3 -e 3 \
    -i /projects/b1108/studies/mwmh/data/processed/neuroimaging/fmriprep_23.1.4/sub-MWMH212/ses-2/func/sub-MWMH212_ses-2_task-rest_space-T1w_desc-preproc_bold.nii.gz \
    -r /projects/b1108/studies/mwmh/data/processed/neuroimaging/surf/sub-MWMH212/ses-2/anat/fs_T1w.nii.gz \
    -t /projects/b1108/studies/mwmh/data/processed/neuroimaging/fmriprep_23.1.4/sub-MWMH212/ses-2/anat/sub-MWMH212_ses-2_from-T1w_to-fsnative_mode-image_xfm.txt \
    -o /projects/b1108/studies/mwmh/data/processed/neuroimaging/surf/sub-MWMH212/ses-2/func/sub-MWMH212_ses-2_task-rest_space-fsnative_desc-preproc_bold.nii.gz

But got a bus error when I ran it. I tried increasing the memory I requested for the interactive node from 10G, to 20G, to 100G, but I am still getting the bus error. How might I fix this problem?

@cookpa
Copy link
Member

cookpa commented Feb 22, 2024

Bus error is unusual, can you try adding --float and turning on --verbose, and sending output?

@cookpa
Copy link
Member

cookpa commented Feb 22, 2024

This works for me with ANTs 2.3.5:

mri_convert /appl/freesurfer-7.2.0/subjects/fsaverage6/mri/T1.mgz /tmp/fs_T1w.nii.gz
antsApplyTransforms -d 3 -e 3 -v 1 \
 -r /tmp/fs_T1w.nii.gz \
 -t anat/sub-03_ses-MR1_rec-norm_from-T1w_to-fsnative_mode-image_xfm.txt \
 -o /tmp/bold_deformed.nii.gz \
 -i func/sub-03_ses-MR1_task-rest_dir-AP_run-1_space-T1w_desc-preproc_bold.nii.gz  \
 --float

@butellyn
Copy link
Author

Oh! That made it pretty far. It got to TR 789 out of 1110 and then said "Killed":

Using single precision for computations.
Input time-series image: /projects/b1108/studies/mwmh/data/processed/neuroimaging/fmriprep_23.1.4/sub-MWMH212/ses-2/func/sub-MWMH212_ses-2_task-rest_space-T1w_desc-preproc_bold.nii.gz
Reference image: /projects/b1108/studies/mwmh/data/processed/neuroimaging/surf/sub-MWMH212/ses-2/anat/fs_T1w.nii.gz

The composite transform comprises the following transforms (in order):

  1. /projects/b1108/studies/mwmh/data/processed/neuroimaging/fmriprep_23.1.4/sub-MWMH212/ses-2/anat/sub-MWMH212_ses-2_from-T1w_to-fsnative_mode-image_xfm.txt (type = AffineTransform)
    =============================================================================
    Default pixel value: 0
    Interpolation type: LinearInterpolateImageFunction
    Applying transform(s) to time point 0 (out of 1110).
    Applying transform(s) to time point 1 (out of 1110).
    Applying transform(s) to time point 2 (out of 1110).
    ...
    Applying transform(s) to time point 787 (out of 1110).
    Applying transform(s) to time point 788 (out of 1110).
    Applying transform(s) to time point 789 (out of 1110).
    Killed

@cookpa
Copy link
Member

cookpa commented Feb 23, 2024

Ok that is a lot of volumes.

I/O changes proposed in #1555 might help, but for now I think you'll have to split the time series with ImageMath and then apply the warps. Then maybe you can re-assemble with ImageMath but if it runs out of memory you might need to use another tool that supports streaming.

@butellyn
Copy link
Author

Thanks for the advice!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants