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

Discrepancy between nibabel's as_closest_canonical and FreeSurfer's mri_convert #518

Closed
oesteban opened this Issue Mar 20, 2017 · 3 comments

Comments

Projects
None yet
3 participants
@oesteban
Copy link

commented Mar 20, 2017

Playing around orientations, I have an example image for which mri_info gives me this:

          type: nii
    dimensions: 256 x 256 x 186
   voxel sizes: 0.8984, 0.8984, 0.9000
          type: FLOAT (3)
           fov: 229.990
           dof: 0
        xstart: -115.0, xend: 115.0
        ystart: -115.0, yend: 115.0
        zstart: -83.7, zend: 83.7
            TR: 7.24 msec, TE: 0.00 msec, TI: 0.00 msec, flip angle: 0.00 degrees
       nframes: 1
       PhEncDir: UNKNOWN
ras xform present
    xform info: x_r =   0.0000, y_r =   0.0000, z_r =  -1.0000, c_r =    -1.8686
              : x_a =   0.0000, y_a =  -1.0000, z_a =   0.0000, c_a =    15.5558
              : x_s =  -1.0000, y_s =   0.0000, z_s =   0.0000, c_s =     9.8568
Orientation   : IPL
Primary Slice Direction: sagittal

voxel to ras transform:
                0.0000   0.0000  -0.9000    81.8314
                0.0000  -0.8984   0.0000   130.5510
               -0.8984   0.0000   0.0000   124.8520
                0.0000   0.0000   0.0000     1.0000

voxel-to-ras determinant 0.72641

ras to voxel transform:
               -0.0000  -0.0000  -1.1131   138.9715
                0.0000  -1.1131   0.0000   145.3150
               -1.1111   0.0000   0.0000    90.9238
                0.0000   0.0000   0.0000     1.0000

So, I start with an image in IPL orientation and aligned with the standard axes. Using nibabel to read these parameters, I get exactly the same orientation code and affine.

If I use mri_convert --out_orientation RAS -i input.nii.gz -o output_RAS.nii.gz, I get the following:

          type: nii
    dimensions: 256 x 256 x 186
   voxel sizes: 0.8984, 0.8984, 0.9000
          type: FLOAT (3)
           fov: 229.990
           dof: 0
        xstart: -115.0, xend: 115.0
        ystart: -115.0, yend: 115.0
        zstart: -83.7, zend: 83.7
            TR: 7.24 msec, TE: 0.00 msec, TI: 0.00 msec, flip angle: 0.00 degrees
       nframes: 1
       PhEncDir: UNKNOWN
ras xform present
    xform info: x_r =   1.0000, y_r =   0.0000, z_r =   0.0000, c_r =    -1.8686
              : x_a =   0.0000, y_a =   1.0000, z_a =   0.0000, c_a =    15.5558
              : x_s =   0.0000, y_s =   0.0000, z_s =   1.0000, c_s =     9.8568
Orientation   : RAS
Primary Slice Direction: axial

voxel to ras transform:
                0.8984   0.0000   0.0000  -116.8638
                0.0000   0.8984   0.0000   -99.4394
                0.0000   0.0000   0.9000   -73.8432
                0.0000   0.0000   0.0000     1.0000

voxel-to-ras determinant 0.72641

ras to voxel transform:
                1.1131  -0.0000  -0.0000   130.0799
               -0.0000   1.1131  -0.0000   110.6850
               -0.0000  -0.0000   1.1111    82.0480
                0.0000   0.0000   0.0000     1.0000

However, using nb.as_closest_canonical I get:

affine = [[   0.89999998    0.            0.          -84.66859758]
         [   0.            0.89840001    0.          -98.54100734]
         [   0.            0.            0.89840001 -104.24000484]
         [   0.            0.            0.            1.        ]] 
shape = (186, 256, 256)

So the centers of images would not match, and the image matrix axes have been reordered as well.

Why is this happening?

@matthew-brett

This comment has been minimized.

Copy link
Member

commented Apr 1, 2017

I don't know what algorithm mri_convert is using. Nibabel is just permuting / flipping the voxel axes to give the closest to RAS voxel orientation. I guess nri_convert is not doing that, because I was expecting the canonical shape to be (186, 256, 256) as nibabel has it. So perhaps mri_convert is doing some resampling to make its output image.

What happens if you resample the mri_convert output onto the nibabel as_closest_canonical output - do the voxels correspond?

from nibabel.processing import resample_from_to
converted_resampled = resample_from_to(converted, nibabel_converted)
@oesteban

This comment has been minimized.

Copy link
Author

commented Apr 5, 2017

I'll try this. But now I see your point. For some reason mri_convert is resampling the data to keep the same sampling matrix. That's weird.

@effigies

This comment has been minimized.

Copy link
Member

commented Sep 5, 2017

@oesteban Closing for now. If there's something actionable here, can you reopen?

@effigies effigies closed this Sep 5, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.