Registration problems when viewing segmentation results in MRIcron or SPM

292 views
Skip to first unread message

Lorenz

unread,
Jun 17, 2020, 3:49:17 AM6/17/20
to ashs-users
Dear group,

this question could be related to either ASHS or to ITK-Snap.
My very first use of ASHS with the atlas for 3T older adults has been successful - when viewing the segmentation in ITK-Snap, everything looks perfect.
However, when using different viewers (MRIcron or SPM CheckReg), the segmented masks are not in register with the structural scan anymore.
(I use SPM for further analyses of the functional images, so this really should be correct.)
I thought that the Nifti header should contain the relevant coordinate information. Could there be any differences between viewers?
Do I need to apply a transformation to the segmentation result?

Best regards,
Lorenz

G Joue (NIN)

unread,
Jun 17, 2020, 5:47:44 AM6/17/20
to Lorenz, ashs-users
Hi Lorenz,

I'm sure there is someone out there who is more qualified to answer your
question/explain this, but I had a registration problem switching
between ASHS, ITK, SPM and FSL -- and I am still a bit shaky about this
(and it's also strongly discouraged by a number of developers -- maybe
another reason to go NiPype which interfaces across these tools), and
although my problem was different to yours, here is the info that I have
collected in case it helps you troubleshoot your problem.

All these different tools indeed interpret NIFTI headers differently and
hence can display images differently. Apparently ITK (by the way, ANTs
registration tools follow ITK convention) has a different way of seeing
"registered" compared to SPM or AFNI.

First thing to check is that the origin and direction are the same
between your images -- if they are not, then they are not considered
coregistered. I guess you can use either ITK::c3d, ANTs::PrintHeader ,
or FSL::fslhd commands, or even Matlab or SPM to check your NIFTI
headers. I'm assuming that the voxel spacing and image dimensions
between your images are the same because ITK-Snap will not allow you to
overlay a segmentation on an image with those being different in the two
(BUT note you can open the segmentation as an "additional image" even if
the voxel spacing and image dimensions are not the same for all images
opened, similarly in SPM's coreg check display).

(For others who might have the same problem I had: my ASHS segmentations
did not look coregistered to my TSE structural in ITK-snap, although
theoretically they were coregistered -- and this ended up being a
problem that they ended up in different physical spaces, as indicated by
them having different origins -- even though I had coregistered all my
images and then ran ASHS, at least I thought so, for some reason, the
origin between my ASHS segmentations were different to my TSEs -- I
fixed this by using ANTs::CopyImageHeaderInformation to copy just the
origin of my TSE images to my ASHS segmentation.s)


SPM, MRIcron, ASHS, ITK and FSL have different ways of working with
DICOM orientation information and encoding native space. There is the
sform (linear) and qform (rotatation/quarternion) matrices which encode
space/how to convert between voxel coordinates and "real world"/mm
coordinates. Each has its own advantages -- apparently sform is better
for figuring out starting alignment estimates, and qform for figuring
out native space. Therefore, warping might work with qform (ignoring any
sform of the fixed image) and registration will actually have worked
properly but depending on how your viewer interprets the NIFTI header,
it might just look like it didn't work.

ITK (like ANTs registration tools) works in LPS space like DICOM images
and works with rotation (quarternion/qform) rather than affine
transformation (sform). It ignores sform and during certain processes
even replaces existing sform with zeros, so you'll lose any info in the
sform.

AFNI works in RAI-/LPI+ coordinate order by default, SPM in LPI.
Not sure about AFNI, but SPM, MRIcro, FSL and Mango prefer the sform
matrix, and only newer SPM versions update both sform and qform to try
and keep things consistent.


Hope that gives you some leads -- lots of luck (and please post your
solution)!
Gina
> --
> You received this message because you are subscribed to the Google
> Groups "ashs-users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to ashs-users+...@googlegroups.com
> <mailto:ashs-users+...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ashs-users/818e89ae-b2d3-43a8-a37a-ffeb10426d07o%40googlegroups.com
> <https://groups.google.com/d/msgid/ashs-users/818e89ae-b2d3-43a8-a37a-ffeb10426d07o%40googlegroups.com?utm_medium=email&utm_source=footer>.

lo...@hrz.tu-chemnitz.de

unread,
Mar 4, 2021, 10:51:47 AM3/4/21
to ashs-users
The solution was easier than expected, I guess this was a beginner's mistake, I'm new to handling .nii files.
I just needed to copy the header/transformation info. into the segementation (after resampling).
The original T1 image has dim. 320x320x240. The segmentation result has dim 320x640x240, for some unknown reason.
This worked:
c3d T1scan.nii segmentation.nii -resample 320x320x240 -o segmentation_resampled.nii
c3d T1scan.nii segmentation_resampled.nii -copy-transform -o segmentation_resampled_copy-transform.nii

Sounds like a very simple beginner's issue, but I'm really happy to have learned this. Looking forward to doing analyses with my new ASHS-based ROI masks!

lo...@hrz.tu-chemnitz.de

unread,
Oct 14, 2021, 6:23:22 AM10/14/21
to ashs-users
Update:
I found out that the solution which I previously posted above is flawed. Luckily, I found out how to properly fix this.
Let's get back to my starting point:
I want to use ASHS to segment T1 scans (0.85mm isotropic, 320x320x240 voxels)
The segmentation results based on the T1 OA atlas (Penn Memory center) comes in dimension 320x640x480.
Simply reslicing to 320x320x240 and copying the Nifti header transformation from the T1 scan still resulted in registration problems when using SPM or MRIcron to view the segmentation along with the T1 scan.
After reading some details about the sform/qform transformations, I came up with this solution which finally solved the problem:
 
1) In the ASHS segmentation, extract the voxels of interest (e.g., with a value of 10 for the entorhinal cortex).
Im Matlab / SPM code, this would be

        read_segmented = spm_vol('subjectID_left_heur_lfseg.nii.gz'');             
        EC_mask_hires = read_segmented.private.dat(:,:,:)==10;
        EC_mask_hires_outfile = read_segmented;
        EC_mask_hires_outfile.fname = char(strcat(image_path, subj_ID, '_', hemi_string,'_', str_segmentation,'_EC_mask_hires.nii'));                         
        EC_mask_hires_outfile.private.dat(:,:,:) = EC_mask_hires; 

2) Copy the transformation from the Nifti header of the T1 scan to the extracted EC voxel image, but apply a correction for the change in voxel size in dimensions 2 and 3.
This is achieved by multiplying the second and third column of the transformation matrix by a value of 0.5:

        EC_mask_hires_outfile.mat = T1_scan.mat;  
        EC_mask_hires_outfile.mat(:, 2:3) = 0.5*T1_scan.mat(:, 2:3);
        spm_write_vol(EC_mask_hires_outfile, EC_mask_hires_outfile.private.dat(:,:,:))
 
3) After supplying the correct transformation to the EC mask in dimension 320x640x480, we interpolate this mask to the T1 dimension of 320x320x240:

        input{1} = T1_scan.fname;
        input{2} = EC_mask_hires_outfile.fname;                                        
        outfile_320x320x240_name = char(strcat(image_path, subj_ID, '_', hemi_string, '_', str_segmentation, '_EC_mask_T1res.nii'));             
        spm_imcalc(input, outfile_320x320x240_name, '(i1 > 0).*i2');

This mask now has the correct transformation when opened using SPM or MRIcron.

Hope this could be helpful for anyone else. Feedback is welcome.

Lorenz
Reply all
Reply to author
Forward
0 new messages