-
Notifications
You must be signed in to change notification settings - Fork 7
MRI: rendering examples
close all; clear all;
targ=MRIread('/Applications/freesurfer/subjects/fsaverage/mri/orig.mgz');
subject='fsaverage';
targ_reg=eye(4);
etc_render_fsbrain('surf','orig','vol_reg',targ_reg,'vol',targ,'subject',subject,'hemi','rh');
return;
Overlay functional/diffusion MRI data on structural MRI. Registration between volumes of different slice prescriptions may occur.
close all; clear all;
targ=MRIread('/Users/fhlin_admin/workspace/7t_music_skku/subjects/SUB1A/mri/orig.mgz');
subject='SUB1A';
targ_reg=eye(4);
dti=MRIread('../unpack/bold/008/fmcprstc.nii.gz');
% do registration between pre- and post-OP by the following command:
%
% cd /Users/fhlin_admin/workspace/seeg/subjects/s057/tmp
% bbregister --s s057 --mov ../../../s057/DTI/nodif_brain.nii.gz --init-coreg --reg register.dat --t2
%
% %check registration
% tkregisterfv --mov ../../../s057/DTI/nodif_brain.nii.gz --reg register.dat --surfs
%dti_reg=etc_read_xfm('file_xfm','/Users/fhlin_admin/workspace/7t_music_skku/subjects/SUB4A/tmp/register.dat'); %for MAC/Linux
%dti_reg=etc_read_xfm('file_xfm','D:\fhlin\Users\fhlin_admin\workspace\seeg\subjects\s057\tmp\register.dat'); %for PC
dti_reg=etc_read_xfm('file_xfm','bb_register_init.dat');
%dti_reg=etc_read_xfm('file_xfm','bb_register_008.dat');
dtim=MRIvol2vol(dti,targ,dti_reg);
%%%%% if needed, use the registration toool ('k' in etc_render_fsbrain) to
%%%%% register manually and expert the registration matrix as
%%%%% `overlay_xfm`. Then use the product dti_reg*overlay_xfm as the
%%%%% transformation
% dtim=MRIvol2vol(dti,targ,dti_reg*overaly_xfm);
%load the Talairach transformation matrix from the "pre-OP" data
talxfm=etc_read_xfm('file_xfm','/Users/fhlin_admin/workspace/7t_music_skku/subjects/SUB4A/mri/transforms/talairach.xfm'); %for MAC/Linux
%talxfm=etc_read_xfm('file_xfm','D:\fhlin\Users\fhlin_admin\workspace\seeg\subjects\s057\mri\transforms\talairach.xfm'); %for PC
etc_render_fsbrain('surf','orig','hemi','rh','subject',subject,'vol',targ,'overlay_vol',dtim,'overlay_threshold',[100 500]);
return;
Use the toolbox to morph individual's T1-weighted MRI to the template (MNI305, subject "fsaverage"). The key is to calculate the transformation matrix correctly.
close all; clear all;
setenv('SUBJECTS_DIR','/Users/fhlin_admin/workspace/seeg/subjects/'); %for MAC/Linux
%setenv('SUBJECTS_DIR','D:\fhlin\Users\fhlin_admin\workspace\seeg\subjects'); %for PC
mri=MRIread('/Users/fhlin_admin/workspace/seeg/subjects/s031/mri/T1.mgz'); %for MAC/Linux
%mri=etc_MRIread('D:\fhlin\Users\fhlin_admin\workspace\seeg\subjects\s031\mri\orig.mgz'); %for PC
%load the Talairach transformation matrix from the "post-OP" data
talxfm=etc_read_xfm('file_xfm','/Users/fhlin_admin/workspace/seeg/subjects/s031/mri/transforms/talairach.xfm'); %for MAC/Linux
%talxfm=etc_read_xfm('file_xfm','D:\fhlin\Users\fhlin_admin\workspace\seeg\subjects\s031\mri\transforms\talairach.xfm'); %for PC
template=MRIread('/Applications/freesurfer/subjects/fsaverage/mri/T1.mgz');
%inv(mri.vox2ras)*inv(talxfm)*template.vox2ras; %<<<< Vox2Vox matrix
%inv(mri.vox2ras)*inv(talxfm)*template.vox2ras; %<<<< tkRAS2tkRAS matrix
mrim=MRIvol2vol(mri,template,mri.tkrvox2ras*inv(mri.vox2ras)*inv(talxfm)*template.vox2ras*inv(template.tkrvox2ras)); %tkRAS-to-tkRAS
etc_render_fsbrain('surf','orig','hemi','rh','subject','fsaverage','vol',template,'overlay_vol',mrim,'overlay_threshold',[50 200]);
return;
For comparison, the spatial normalization (morphing) can also be done by the command line mri_vol2vol
in FreeSurfer.
mri_vol2vol --mov orig.mgz --targ $FREESURFER_HOME/average/mni305.cor.mgz --xfm transforms/talairach.xfm --o orig-in-mni305.mgz
Then you can examine the result, which should be similar to images obtained above. The difference is likely due to methods of interpolation. In Matlab implementation, the morphing was done by the nearest-neighbor search. The command line mri_vol2vol
was done by trilinear interpolation by default.
%command line mri_vol2vol
mrim_compare=MRIread('/Users/fhlin_admin/workspace/seeg/subjects/s031/mri/orig-in-mni305.mgz');
etc_render_fsbrain('surf','orig','hemi','rh','subject','fsaverage','vol',template,'overlay_vol',mrim_compare,'overlay_threshold',[50 200]);
The MNI305 template typically comes with the 2-mm resolution with a 76x76x93 image matrix. This is the volume resolution and dimension for $FREESURFER_HOME/average/mni305.cor.subfov2.mgz. The following script shows how to morph the individual's T1 MRI to such a template.
close all; clear all;
setenv('SUBJECTS_DIR','/Users/fhlin_admin/workspace/seeg/subjects/'); %for MAC/Linux
%setenv('SUBJECTS_DIR','D:\fhlin\Users\fhlin_admin\workspace\seeg\subjects'); %for PC
mri=MRIread('/Users/fhlin_admin/workspace/seeg/subjects/s031/mri/T1.mgz'); %for MAC/Linux
%mri=etc_MRIread('D:\fhlin\Users\fhlin_admin\workspace\seeg\subjects\s031\mri\orig.mgz'); %for PC
%load the Talairach transformation matrix from the "post-OP" data
talxfm=etc_read_xfm('file_xfm','/Users/fhlin_admin/workspace/seeg/subjects/s031/mri/transforms/talairach.xfm'); %for MAC/Linux
%talxfm=etc_read_xfm('file_xfm','D:\fhlin\Users\fhlin_admin\workspace\seeg\subjects\s031\mri\transforms\talairach.xfm'); %for PC
template=MRIread('/Applications/freesurfer/average/mni305.cor.subfov2.mgz');
template_reg=etc_read_xfm('file_xfm','/Applications/freesurfer/average/mni305.cor.subfov2.reg'); %for MAC/Linux
%inv(mri.vox2ras)*inv(talxfm)*template.vox2ras; %<<<< Vox2Vox matrix
%inv(mri.vox2ras)*inv(talxfm)*template.vox2ras; %<<<< tkRAS2tkRAS matrix
mrim=MRIvol2vol(mri,template,mri.tkrvox2ras*inv(mri.vox2ras)*inv(talxfm)*template.vox2ras*inv(template.tkrvox2ras)); %tkRAS-to-tkRAS
etc_render_fsbrain('surf','orig','hemi','rh','subject','fsaverage','vol_reg',template_reg,'vol',template,'overlay_vol',mrim,'overlay_threshold',[50 200]);
return;
Alternatively, you can also morph the template (MNI305 brain in 2-mm resolution) to individual's anatomical space.
mrim=MRIvol2vol(template,mri,inv(mri.tkrvox2ras*inv(mri.vox2ras)*inv(talxfm)*template.vox2ras*inv(template.tkrvox2ras))); %tkRAS-to-tkRAS
etc_render_fsbrain('surf','orig','hemi','rh','subject','s031','vol_reg',eye(4),'vol',mri,'overlay_vol',mrim,'overlay_threshold',[50 200]);