Skip to content

anat affine appears off for ds000114 between data and fmriprep output #624

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

Closed
satra opened this issue Jul 30, 2017 · 10 comments
Closed

anat affine appears off for ds000114 between data and fmriprep output #624

satra opened this issue Jul 30, 2017 · 10 comments

Comments

@satra
Copy link

satra commented Jul 30, 2017

any reason why the T1 brainmask output from fmriprep has different affines from original T1 of the dataset? is this because of the conform step?

$ mri_info ../sub-01/anat/sub-01_t1w_brainmask.nii.gz 
Volume information for ../sub-01/anat/sub-01_t1w_brainmask.nii.gz
          type: nii
    dimensions: 256 x 156 x 256
   voxel sizes: 1.000000, 1.299473, 1.000000
          type: FLOAT (3)
           fov: 256.000
           dof: 0
        xstart: -128.0, xend: 128.0
        ystart: -101.4, yend: 101.4
        zstart: -128.0, zend: 128.0
            TR: 0.00 msec, TE: 0.00 msec, TI: 0.00 msec, flip angle: 0.00 degrees
       nframes: 1
       PhEncDir: UNKNOWN
       FieldStrength: 0.000000
ras xform present
    xform info: x_r =   0.9992, y_r =  -0.0393, z_r =   0.0096, c_r =    -2.1763
              : x_a =   0.0395, y_a =   0.9989, z_a =  -0.0269, c_a =    22.5293
              : x_s =  -0.0085, y_s =   0.0272, z_s =   0.9996, c_s =    -8.5970
Orientation   : RAS
Primary Slice Direction: axial

voxel to ras transform:
                0.9992  -0.0510   0.0096  -127.3170
                0.0395   1.2980  -0.0269   -80.3350
               -0.0085   0.0354   0.9996  -138.2132
                0.0000   0.0000   0.0000     1.0000

voxel-to-ras determinant 1.29947

ras to voxel transform:
                0.9992   0.0395  -0.0085   129.2109
               -0.0302   0.7687   0.0209    60.7968
                0.0096  -0.0269   0.9996   137.2195
                0.0000   0.0000   0.0000     1.0000

$ mri_info ../../../sub-01/ses-test/anat/sub-01_ses-test_T1w.nii.gz 
Volume information for ../../../sub-01/ses-test/anat/sub-01_ses-test_T1w.nii.gz
          type: nii
    dimensions: 256 x 156 x 256
   voxel sizes: 1.000000, 1.299376, 1.000000
          type: FLOAT (3)
           fov: 256.000
           dof: 0
        xstart: -128.0, xend: 128.0
        ystart: -101.4, yend: 101.4
        zstart: -128.0, zend: 128.0
            TR: 9.67 msec, TE: 0.00 msec, TI: 0.00 msec, flip angle: 0.00 degrees
       nframes: 1
       PhEncDir: UNKNOWN
       FieldStrength: 0.000000
ras xform present
    xform info: x_r =   0.9991, y_r =  -0.0397, z_r =   0.0125, c_r =     0.1996
              : x_a =   0.0408, y_a =   0.9943, z_a =  -0.0981, c_a =    20.3043
              : x_s =  -0.0085, y_s =   0.0985, z_s =   0.9951, c_s =   -41.2883
Orientation   : RAS
Primary Slice Direction: axial

voxel to ras transform:
                0.9991  -0.0516   0.0125  -125.2639
                0.0408   1.2920  -0.0981   -73.1330
               -0.0085   0.1280   0.9951  -177.5543
                0.0000   0.0000   0.0000     1.0000

voxel-to-ras determinant 1.29938

ras to voxel transform:
                0.9991   0.0408  -0.0085   126.6200
               -0.0306   0.7652   0.0758    65.5996
                0.0125  -0.0981   0.9951   171.0755
                0.0000   0.0000   0.0000     1.0000
@effigies
Copy link
Member

To clarify, the conform step only modifies the affine if there are multiple images with different dimensions/zooms. This is a necessary precondition to merging, and the only way to avoid it is to have two images in the same space, or remove one of the T1w images before running FMRIPREP.

If it would be useful to have the transform matrix from the inputs T1w images to the T1w_preproc image, it looks like the transform for the conform step is just:

transform_affine = np.dot(linalg.inv(T1w.affine), T1w_preproc.target_affine)

mri_robust_template can be made to output the transforms for the final merge step, which can be combined with the conform transforms to get the total transform.

@chrisgorgo
Copy link
Contributor

@satra it seems that the conform step is unavoidable in multi T1w. Is there a need for providing affine matrices going from original to conformed images?

@satra
Copy link
Author

satra commented Aug 4, 2017

@chrisfilo - perhaps fmriprep should be just annotated to indicate that T1_preproc and any of the raw T1s are not in alignment. i'm ok with not needing them.

@chrisgorgo
Copy link
Contributor

I believe this is only the case when there are multiple T1w images. The reports should provide this information now.

@effigies
Copy link
Member

effigies commented Aug 4, 2017

Tagged this with documentation. I think a comprehensive review of the docs would be good, to make sure concepts like this are clear without too much digging.

@oesteban
Copy link
Member

As usual, @satra foresaw back on July 30 that we would find that many tools mess up with affines on October 8 and reported it here.

Now, acknowledging that wrong affines were the source of #710 and #708 I think we can close this issue. #743 should fix this.

However, since this is a really delicate issue, I'll make sure we double check on all affines we produce in #745 and we add the appropriate documentation.

@effigies
Copy link
Member

Just a quick point: This is about the T1w affines changing, not the alignment issues we've just been dealing with. #726 is a response to that, but we hadn't settled on an ultimate solution there.

@oesteban
Copy link
Member

nipreps/niworkflows#202 (comment)

I think this falls in category 1: when we are "moving" within the same space (in this case, identity transform), the output should have the same affine as the input (even if it is originally wrong).

We probably want to make these policies very clear in the documentation, following what you were suggesting since the beginning.

@effigies
Copy link
Member

I might be misunderstanding the point you're making, but it sounds like you're saying the transform from input T1w images to the final T1w image should be the identity and that Satra was reporting an error. We can't always stay in the same space with multiple T1w images. If they're differently shaped or at all misaligned, constructing the template requires reslicing, rigid motion, or both.

@oesteban
Copy link
Member

Oh right, this issue really popped up because we had several T1w images. You are right: this problem would not be covered by those two categories. I'll add this as a 3rd category.

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

No branches or pull requests

4 participants