dki-questions > Preprocessing method?
Showing 1-12 of 12 posts
Display:
Results per page:
Sep 3, 2015  09:09 PM | Christina Gancayco
Preprocessing method?
Hello,

I was wondering if anyone here would be willing to share their preferred pipeline for preprocessing DKI data, particularly when it comes to normalizing to standard space? Do you prefer to use FSL, SPM, etc when working with the DKE or Fiber Tracking module?

Thank you!
Christina
Sep 4, 2015  07:09 PM | Russell Glenn - Medical University of South Carolina
RE: Preprocessing method?
Hi Christina,

DKE has some preprocessing scripts that work from dicoms, but there are some other options as well.

I like working with MRIcron for generating gradient tables and nifti images, and I have some scripts that work from their dcm2nii output, which I am happy to share. The basic idea is just co-register b0 images using SPM then average things and then create a 4D nifti image volume for DKE.

Normalizing tractography to standard space is a little more tricky. The DKE Tractography module works in image space with the bottom of the image volume at (0,0,0) and the tract coordinates in LPS. This was done for compatibility with visualization software I was working with (eg TrackVis and DSI Studio).

After running DKE and the DKE Tractography module, the FT_struct.mat file contains some of the info you need.

Do something like:

    S = load('~/FT_struct.mat');
    vox_to_ras = S.hdr.mat([S.permute_img 4],:)*[diag(S.invert_img) double(S.invert_img==-1)'.*S.hdr.dim(S.permute_img)'+S.shift*[1;1;1];0 0 0 1];

vox_to_ras is the affine transformation from image space (in LPS) to whatever coordinate system is specified in the nifti header, which can be applied to each tract in the FT_DKI.mat file.

This gets you to whatever space SPM has the images in. Then you would have to do a normalization step using SPM (or something else) to get to whatever standard space you want, which will require a non-linear transformation. You then have to apply that deformation to each of the tracts as well. I know of one script to do this from the VISTA Lab (mrAnatXformCoords.m).

Although tempting, it is not advisable to do the non-linear step before estimating the tracts. This is because there is no way that I'm aware of to deform the gradient tables (or tensors) for each region of the image which would probably cause funny stuff to happen when estimating the fiber bundle orientations.

Hope that help,

Russell
Sep 8, 2015  07:09 PM | Christina Gancayco
RE: Preprocessing method?
Thanks, Russell! This was very helpful. I am new to SPM--is there a procedure that you find works particularly well with normalizing the tractography to MNI space?
Sep 9, 2015  01:09 PM | Russell Glenn - Medical University of South Carolina
RE: Preprocessing method?
Hi Christina,

No problem! Transformations are no fun. I've attached a potential solution , but I'm sure there are other ways to do this. I would be curious what others do as well... The easiest place for this to go wrong is in the actual normalization, which can be tested with SPM's GUI if there are issues (check if the template and source images overlay after normalization). I believe everything will work without having to mess with it, but just check to make sure everything looks ok with your data.

Best,

Russell
Sep 9, 2015  10:09 PM | Russell Glenn - Medical University of South Carolina
RE: Preprocessing method?
Hey Christina,

I found an error in the script I sent before, so I removed that one and corrected the error in the attached script. Sorry about that!

Russell
Sep 16, 2015  08:09 PM | Christina Gancayco
RE: Preprocessing method?
Thank you for the script! It's been really helpful in figuring out the steps for normalizing my data. I had a question about the FT.mat vs. the FT.trk--I loaded them both in Matlab and noticed the coordinates for each tract were different. I was wondering what the difference is, and should I exclusively use the FT.trk over the FT.mat in these transformations?
Sep 16, 2015  08:09 PM | Russell Glenn - Medical University of South Carolina
RE: Preprocessing method?
Hi Christina,

No problem. I'm glad it works for you, and it has been very useful for me as well.

The coordinates in the FT.mat file are in image space so you can do things like ceil(TRK{1}) and that gives you the voxel indices for each coordinate for the first tract. Right before making the .trk file, these are scaled up by their voxel dimensions so the tracts are in a space with coordinates that match the real-world lengths of the tracts (in mm). If you let vox be a vector of voxel dimensions (eg vox = [3 3 3]), then bsxfun(@times,TRK{1},vox) = trk(1).matrix, so you can use whichever one you want, you just have to know if you want the actual length or the image representation, vox_to_ras (which is similar to the affine transformation in the nifti header) comes from the image space, for example. Sorry for the confusion! I need to put something about all of this clearly in the manual....

Best,

Russell
Sep 17, 2015  06:09 PM | Christina Gancayco
RE: Preprocessing method?
Thanks! I have yet another question...sorry!

I've converted the tracts to RAS mm with vox_to_ras, warped them to standard space with an affine matrix output by FSL's TBSS when I registered the FA map, and converted them back to voxel coordinates. When I opened my warped FA map and tracts in DSI studio though, they're not quite aligned--maybe off by a few voxels in each direction. When I opened the original FA map in mricron, it seems like the offset of the center voxel from the AC is approximately the same offset I see in DSI Studio.

Should I be taking account of this offset before I apply vox_to_ras and my other transformations? Or does DSI studio automatically set the center voxel to the AC when you import a Nifti? The center voxels are definitely different in mricron and DSI studio.
Sep 17, 2015  07:09 PM | Russell Glenn - Medical University of South Carolina
RE: Preprocessing method?
No worries, but that's a tough one! DSI studio uses image space and doesn't use the same coordinate space as mricron, and DSI studio doesn't apply any shifts. But you could try changing the hdr.image_orientation_patient field in the trk header to [1 0 0 0 1 0] or [-1 0 0 0 -1 0], for LPS and RAS, respectively, if they seem to be flipped. It's more likely that there's just a shift off somewhere though, like you said.

I was looking over the scripts that I adapted from the Vista lab, and there's a point after it converts to MNI when it also applies a qto_ijk transformation from the template image which is just a shift from the template header, and it's not clear to me why this is being applied. I would suggest removing this qto_ijk transformation, but it's hard to say for sure without sitting down and playing with it. 

I'm less sure about the FA map being off in mricron. You can reset this in spm though. In matlab run spm, then click fmri, display, and then use their gui to reorient. This may fix the mricron issue but I'm still suspicious about the DSI studio one. If you do this, sometimes you have to manually reset the hdr.private.mat0 field in the nifti header before normalization :(

What you're doing should work though. Is there a way to verify the tracts in MNI space?
Sep 18, 2015  07:09 PM | Christina Gancayco
RE: Preprocessing method?
I've just been verifying by viewing the transformed tracts and FA maps together in DSI Studio. I'm currently applying some ROI masks to the tracts of a healthy control using Matlab to create a connectivity matrix, so if the resulting matrix seems really off then I'll reorient my original FA image.

I was going through the methods of the Mori lab paper that the Vista Lab cited in their AFQ_SegmentFiberGroups script, and it looks like they also registered each subject's T1-weighted volume to their template and applied that transformation to their tracts as well. Do you think that's worth doing in this case?
Sep 19, 2015  11:09 AM | Russell Glenn - Medical University of South Carolina
RE: Preprocessing method?
Hi Christina,

You are probably right that there was a shift in your the tracts before. I am still not sure what the mrAnatXformCoords.m function is doing so I took it out. But more insidiously, I had assumed the original vox_to_ras transformation wanted the middle of my first voxel to be at (1,1,1), which is what I like to think of as voxel space (because you can just round the coordinates to get your voxel indices), however the middle of the first voxel should have been at (0,0,0) (per SPM conventions???). To emphasize why this confuses me to no end, DSI Studio and Track Vis put the middle of the first voxel at (0.5,0.5,0.5), so the bottom of the image volume is at (0,0,0)... any ways, I believe this is corrected!

I have attached another script which will perform the normalization from DKE output to MNI Image space (attached) and included an example data set which seems to work and I can't see an obvious shift. 

Sorry for the confusion!
Attachment: dke2mni_img.m
Sep 19, 2015  11:09 AM | Russell Glenn - Medical University of South Carolina
RE: Preprocessing method?
Image to go with previous post...