WCHN / CTseg

Brain CT image segmentation, normalisation, skull-stripping and total brain/intracranial volume computation.
GNU General Public License v3.0
55 stars 17 forks source link

Behavior of realign2mni? #6

Closed petteriTeikari closed 4 years ago

petteriTeikari commented 4 years ago

Is it intentional that in the preprocessing, the realign2mni() is not actually applying the MNI alignment to the input data?

Both transformation matrices (origin reset and MNI alignment) are computed, but only the reset origin one is applied to the CT volume?

[Image,M] = reset_origin(Image);

Resetting origin... (reset_origin.m)   ... number of elements in = 1 
 --- Size of the img before reset = 512  512  137
 --- --- Size of the img after reset = 514  504  178

Elapsed time is 2.807755 seconds.

>> M{1}

ans =

    1.0000         0         0    0.2784
         0    1.0000         0   -0.4952
         0         0    1.0000  103.5000
         0         0         0    1.0000

[Image,M] = realign2mni(Image,M)

Realigning to MNI...   ... number of elements in = 1
 --- Size of the img before realign2mni = 514  504  178
 --- --- Size of the img after realign2mni = 514  504  178

Elapsed time is 36.333279 seconds.

>> M{1}

ans =

    0.9971    0.0747   -0.0152   17.9785
   -0.0762    0.9789   -0.1895    1.0920
    0.0007    0.1901    0.9818   92.2344
         0         0         0    1.0000

Image{1} = 

NIFTI object: 1-by-1
            dat: [514×504×178 file_array]
            mat: [4×4 double]
     mat_intent: 'Aligned'
           mat0: [4×4 double]
    mat0_intent: 'Aligned'
        descrip: 'CT'

Image{1}.mat =

   -0.4421   -0.0338    0.0007  104.7872
   -0.0331    0.4340    0.1901 -118.8067
    0.0067   -0.0840    0.9818  -56.7537
         0         0         0    1.0000

Image{1}.mat0 =

   -0.4434         0         0  114.1649
         0    0.4434         0 -111.9482
         0         0    1.0000  -89.5000
         0         0         0    1.0000

And similarly it seems that in the output folder, only the reset origin is saved to the header?

             Filemoddate: '04-Nov-2019 17:01:30'
                 Filesize: 184448224
                  Version: 'NIfTI1'
              Description: 'Bias Field Corrected Image'
                ImageSize: [514 504 178]
          PixelDimensions: [0.4434 0.4434 1]
                 Datatype: 'single'
             BitsPerPixel: 32
               SpaceUnits: 'Millimeter'
                TimeUnits: 'Second'
           AdditiveOffset: 0
    MultiplicativeScaling: 1
               TimeOffset: 0
                SliceCode: 'Unknown'
       FrequencyDimension: 0
           PhaseDimension: 0
         SpatialDimension: 0
    DisplayIntensityRange: [0 0]
            TransformName: 'Sform'
                Transform: [1×1 affine3d]
                  Qfactor: -1
                      raw: [1×1 struct]

Transform =

   -0.4434         0         0         0
    0.0000    0.4434         0         0
         0         0    1.0000         0
  114.0000 -112.0000   15.0000    1.0000
petteriTeikari commented 4 years ago

And as the written segmentation outputs are in the resetted space instead of "truly" native in which my other segmentation masks are, is there some options missing, or am I missing something? https://github.com/WCHN/CTseg/blob/c6cd2dab61d6c37b45adde90a7050d0a6da61c10/spm_segment_ct.m#L14

% Write      - What results to write to DirOut:
%                Write.image  = [native image, warped image]          [1 0]
%                Write.native = [native seg, dartel seg]              [1 0]
%                Write.warped = [] [warped seg, warped modulated seg] [0 0]

https://github.com/WCHN/CTseg/blob/c6cd2dab61d6c37b45adde90a7050d0a6da61c10/toolboxes/segmentation-model/code/write_results.m#L308

So which mat is actually propagated there with the default options, the origin reset is applied I assumed, and is there an easy way to turn that off?

https://github.com/WCHN/CTseg/blob/2710377fd3c8d2c2eace4802bb0192961a2d3f33/toolboxes/auxiliary-functions/spm_misc.m#L54

brudfors commented 4 years ago

Hello @petteriTeikari ,

The recent major update+refactoring of the code should have solved this issue.

I am sorry that resolving it took so long. The code was in a very experimental phase when I first uploaded it to GitHub (as you know) and has required significant modifications to work in a general way (improvements to the underlying mathematical models, re-training of the atlas, etc.). However, now it should work well as I have tested it on a large cohort of routine clinical CT images.

Best wishes,

Mikael