Aligned MRI outside brainstorm are no longuer aligned after importation

Hello,

I am working with 2 versions of the MNI template: a 1x1x1 mm version and a 3x3x3 mm one.
I computed FreeSurfer segmentation from the 1x1x1 mm version of the template and imported it into Brainstorm. Then, I imported the downsampled version of the template using "Import MRI". (all MRI subject space)(with no co-registation or reslicing).

When opening the different MRI outside brainstorm, in freeview, everything is aligned.

In Brainstorm, when checking the alignment of the cortex with the MRI, it is aligned when checking on the 1x1x1 MRI. It is completely off when checking the 3x3x3 MRI.

I also noticed that the fiducials are ok on the 1x1x1 MRI but completely wrong on the 3x3x3 (although world coordinates are the same).

1x1x1:

3x3x3:

Then, the surface alignment is also wrong

we can really see it well with the 'manual align tool':

when it's ok for the 1x1x1:

Any idea on how I could fix that ?

thanks a lot,
Edouard

It seems the issue is with the fiducials that are placed using maff8 in the 3-mm version.
After importing 3-mm version MRI, does the cortex get align if you manually edit LPA, RPA and NAS?

i just tried and its still not aligned:

Knowing that when setting the fiducials, i also get the following error:


** Error: The fiducials should be edited only in the first MRI file.


Actually, even if i import the 1x1x1 MRI used for the freesurfer computation, then they are not aligned in brainstorm. Even though they are when opened in freeview:

I assumed they were imported as different subjects.

For each subject, there should be one (default) MRI volume and that is the one that contains the fiducials, which are stored in MRI [mm] (voxel position scaled by the voxel size).

That's strange. This is what I tested here:

  1. Run FreeSurfer 7.3 on ICBM 2009c Nonlinear Asymmetric (NIfTI) from here:
    BIC - The McConnell Brain Imaging Centre: ICBM 152 N Lin 2009
  2. Import Anatomy folder (auto)
  3. Import MRI (NIfTI file from Step 1)
    Everything remains aligned

i will try to put the data on a drive.

When I try to specify the fiducials, the display is weird ? can it be related ?

This seems like a bug when the fiducial cords were set (or copied) to this volume. Each row should be 3 elements. But here it's something else

i put the data here : https://drive.google.com/file/d/11KWsQxmbi_xQmA4rpVoybq7DJ_CpBan9/view?usp=sharing

The folder contains :

  • template with 2 mri : mni152nl_T1_on_333_nifti.nii and mni152nl_T1_on_111_nifti.nii respectively the MRI at 3x3x3 and 1x1x1 mm resolution
  • the freesurfer outout computed on mni152nl_T1_on_111_nifti.nii in mni152nl_T1_on_111_nifti.nii

Let me know if you are able to import the surface and to overlay on top of the 3x3x3 mri.

The issue is the vox2ras transformation in the NIfTI files, it is "incomplete" as it does not center the MRI. Last column in the vox2ras transformation.

vos2ras_nocentered

When the FreeSurfer output is imported, the T1.mgz is now centered (this happens in FS).
Thus is why when the mni152nl_T1_on_333_nifti is imported without coreg, but with slice, it's world origin (left-posterior-inferior corner) appears at the T1 center (which is its world origin).

Note that the world origin in both NIfTI files is in the same place, left-posterior-inferior corner, but they are not registered in this corner but in the center of the volumes.

So, if you want to have the 3mm coregister with the FS output.

  1. Import the FreeSurfer output folder

  2. Add 3mm MRI

  3. Corregister with SPM (this correct the vox2ras, so now the [world 0,0,0] corresponds to the center of the brain)

  4. Reslice.
    Yes: you need the imported 3mm volume to have the same voxel size as 1mm)
    No: you want to have the low resolution volume as it is
    Note: you can always reslice later

  5. Now everything is aligned!!!
    Left: Brainstorm database
    Middle: mni152nl_T1_on_333_nifti_spm_reslice overlayed on MRI T1
    Right: cortex_15002V overlayed on mni152nl_T1_on_333_nifti_spm (not resliced)

Thanks a lot. At first, it made a lot of sense to me.

But there is one thing i don't get. If i run mri_info (function from freesurfer), then i see the vox2ras transformation just fine:

(base) edelaire@perf-imglab07:/NAS/home/edelaire/Documents/data/NeuroDot/2014_Nph_Data_Share/template$ mri_info mni152nl_T1_on_333_nifti.nii
Volume information for mni152nl_T1_on_333_nifti.nii


Primary Slice Direction: axial

voxel to ras transform:
                3.0000   0.0000   0.0000   -70.5000
                0.0000   3.0000   0.0000  -105.0000
                0.0000   0.0000   3.0000   -60.0000
                0.0000   0.0000   0.0000     1.0000

Can it be an issue when loading MRI in brainstorm ?

I tried also on the 1x1x1 and it seems present too:

(base) edelaire@perf-imglab07:/NAS/home/edelaire/Documents/data/NeuroDot/2014_Nph_Data_Share/template$ mri_info mni152nl_T1_on_111_nifti.nii
Volume information for mni152nl_T1_on_111_nifti.nii
          type: nii
    dimensions: 176 x 208 x 176
   voxel sizes: 1.000000, 1.000000, 1.000000
          type: FLOAT (3)
           fov: 176.000
           dof: 1
        xstart: -88.0, xend: 88.0
        ystart: -104.0, yend: 104.0
        zstart: -88.0, zend: 88.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 =   1.0000, y_r =   0.0000, z_r =   0.0000, c_r =     0.0000
              : x_a =   0.0000, y_a =   1.0000, z_a =   0.0000, c_a =   -19.0000
              : x_s =   0.0000, y_s =   0.0000, z_s =   1.0000, c_s =    13.0000
Orientation   : RAS
Primary Slice Direction: axial

voxel to ras transform:
                1.0000   0.0000   0.0000   -88.0000
                0.0000   1.0000   0.0000  -123.0000
                0.0000   0.0000   1.0000   -75.0000
                0.0000   0.0000   0.0000     1.0000

voxel-to-ras determinant 1

ras to voxel transform:
                1.0000   0.0000   0.0000    88.0000
                0.0000   1.0000   0.0000   123.0000
                0.0000   0.0000   1.0000    75.0000
                0.0000   0.0000   0.0000     1.0000

So i looked a bit, at the import function and it seems that both sForm and qForm are defined and that qForm (wrong) is loaded when the correct one seems to be in sForm


K>> nifti.sform

ans =

    3.0000         0         0  -70.5000
         0    3.0000         0 -105.0000
         0         0    3.0000  -60.0000
         0         0         0    1.0000

K>> nifti.qform

ans =

   61.6615         0         0         0
         0   61.7209         0         0
         0         0   61.5116         0
         0         0         0    1.0000

If i force brainstorm to use the sform, then it's working, without calling SPM for realignment:

Is that an issue with the MRI file; or with Brainstorm reading function ?

I'll look further into it

As you reported, the field sform is well read from the NIfTI in Brainstorm.

However, in Brainstorm, the vox2ras transformation can come either from sform or qform. It depends on the codes for each: sform_code and qform_code. Link to code.

If sform_code is not 2, it uses qform (if qform_code is not zero).

This behaviour is different from other software as nibabel (see link), where sform is used if sform_code is not 0. And this was how Brainstorm used to do it, until this

It seems this fix aimed to get the vox2ras from sform IFF the word coordinates were = 2 i.e., Coordinates aligned to another file's, or to anatomical "truth".

To me, the export fix, seem ok. However, I don't see the logic on the import part.


As mentioned above, nibabel prefers sform is its code is not 0. It seems FSL does the same, as well as other softwares. Though ITK preferes qform.

Related information on those NIfTI header fields:

1 Like

Thanks a lot for the help and investigation.

I was able to import and project the fMRI file I was sent to the cortical surface :slight_smile:

In order to match the behaviour in other imaging software (and niftiinfo in Matlab), the imported vox2ras transformation follow this order:

  1. sform if sform_code != 0
  2. qform if qform_code != 0
  3. No transformation if sform_code == 0 and qform_code == 0

Commit: 407142c

Moreover, now the imported vox2ras as well as its xform_code are saved in the MRI file history.
Note that fields [sq]form and [sq]form_code are available in the structure Header.nifti of the MRI file.

Refer to the post above for more detailed information:

@edelaire, with these changes, now you can import directly the mentioned MNI152 template ( 1mm and 3mm) and they will be coregistered.

FYI @Marc.Lalancette

1 Like