Skip to content

Commit

Permalink
Working on mrtrix code
Browse files Browse the repository at this point in the history
  • Loading branch information
francopestilli committed Jul 16, 2014
2 parents cc0a4e6 + 0ff6368 commit f9eaa12
Show file tree
Hide file tree
Showing 364 changed files with 3,265 additions and 9,760 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## Vistasoft

This is the main software repository of the [Vista lab](http://vistalab.stanford.edu) at [Stanford University](http://stanford.edu). It contains Matlab code to perform a variety of analysis on MRI data, including functional MRI and diffusion MRI.
VISTASOFT is the main software repository of the [Vista lab](http://vistalab.stanford.edu) at [Stanford University](http://stanford.edu). It contains Matlab code to perform a variety of analysis on MRI data, including functional MRI and diffusion MRI.

It has the following modules:

Expand All @@ -22,7 +22,7 @@ External dependencies:
- Matlab (2009 or newer)
- SPM8

For documentation, please visit the [lab wiki](http://vistalab.stanford.edu/wiki).
For documentation, please visit the [VISTA lab wiki](http://vistalab.stanford.edu/wiki).


For help with the new mrInit intialization method, please see the [Initialization Page](http://white.stanford.edu/newlm/index.php/Initialization#mrInit).
Expand Down
6 changes: 3 additions & 3 deletions external/camino/camAlignImageToDTI.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ function camAlignImageToDTI(dti_ref_filename,high_res_filename,output_filename,p


% Experiment with xform
ni_src = readFileNifti(high_res_filename);
ni_ref = readFileNifti(dti_ref_filename);
ni_src = niftiRead(high_res_filename);
ni_ref = niftiRead(dti_ref_filename);

ref_dim = ni_ref.dim(1:3);
ref_pixdim = ni_ref.pixdim(1:3);
Expand Down Expand Up @@ -38,4 +38,4 @@ function camAlignImageToDTI(dti_ref_filename,high_res_filename,output_filename,p
% write
dtiWriteNiftiWrapper(new_data, xform, output_filename);

return
return
2 changes: 1 addition & 1 deletion external/camino/camCreateHARDIFitScript.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function camCreateHARDIFitScript(scr_modelfit_filename,scr_after_modelfit_filena
bgthresh = 200;
end
% Volumetric information
raw = readFileNifti(raw_filename);
raw = niftiRead(raw_filename);
vol_dim = raw.dim;
xd = vol_dim(1);
yd = vol_dim(2);
Expand Down
2 changes: 1 addition & 1 deletion external/camino/camFA.m
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ function camFA(dtfit_filename, fa_filename, raw_nifti_filename)
display(cmd);
system(cmd,'-echo');

raw = readFileNifti(raw_nifti_filename);
raw = niftiRead(raw_nifti_filename);

camVoxel2Image( fa_bdouble_filename, fa_nifti_filename, 'double', ...
raw.qto_xyz, 1, raw.dim(1:3) );
Expand Down
2 changes: 1 addition & 1 deletion external/camino/camTrackProjectomeCandidates.m
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function camTrackProjectomeCandidates(cdb_filename,step_size,min_track_length,pd

if ~notDefined('ends_filename')

ends = readFileNifti(ends_filename);
ends = niftiRead(ends_filename);

if max(ends.data(:)>1)
cmd3 = sprintf('procstreamlines -inputfile %s -mintractlength %f -noresample -endpointfile %s -outputfile %s',t2_filename, min_track_length, ends_filename, cdb_filename);
Expand Down
6 changes: 3 additions & 3 deletions external/camino/cam_fix_header.m
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ function cam_fix_header(file_to_fix,file_to_src,file_out)
end

%% Load image files
ni_fix = readFileNifti(file_to_fix);
ni_src = readFileNifti(file_to_src);
ni_fix = niftiRead(file_to_fix);
ni_src = niftiRead(file_to_src);

%% Fix image header
dtiWriteNiftiWrapper(ni_fix.data, ni_src.qto_xyz, file_out);
dtiWriteNiftiWrapper(ni_fix.data, ni_src.qto_xyz, file_out);
16 changes: 8 additions & 8 deletions external/camino/s_cam_compute_track_projections.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
s_cam_definitions;

%% Load image for pathway xforms
ni_seg = readFileNifti(fullfile(mask_dir,seg_filename));
ni_seg = niftiRead(fullfile(mask_dir,seg_filename));
% Calc xform from camino space to acpc space
xform = ni_seg.qto_xyz;
xform(1:3,1:3) = eye(3);
Expand All @@ -16,26 +16,26 @@
% Needs to be in comparison to how else the fiber is connected
fiber_cthresh = 0;
% Gray Matter
ni_gm = readFileNifti(fullfile(mask_dir,'gm.nii.gz'));
ni_gm = niftiRead(fullfile(mask_dir,'gm.nii.gz'));
num_gm_vox = sum(ni_gm.data(:)>0);
num_fibers_gen = num_gm_vox * 10;
% Eccentricity
ni_ecc = readFileNifti(fullfile(mask_dir,'ecc_var_0.1.nii.gz'));
ni_ecc = niftiRead(fullfile(mask_dir,'ecc_var_0.1.nii.gz'));
ni_ecc.data(ni_gm.data==0) = 0;
ecc_vox = ni_ecc.data(ni_ecc.data>0);
num_ret_vox = numel(ecc_vox);
ratio_ret_gm = num_ret_vox / num_gm_vox;
% ROIs
ni_roi = readFileNifti(fullfile(mask_dir,'rois.nii.gz'));
ni_roi = niftiRead(fullfile(mask_dir,'rois.nii.gz'));
ni_roi.data(ni_gm.data==0) = 0;
roi_vox = ni_roi.data(ni_roi.data>0);
num_roi_vox = numel(roi_vox);
ratio_roi_gm = num_roi_vox / num_gm_vox;

%% Occipital exiting connections
% Considering eccentricity
ni_fiber_gm_exit = readFileNifti(fullfile(camino_dir,'tracts_mesd_gm_exit_1cm_ends.nii.gz'));
%ni_fiber_gm = readFileNifti(fullfile(acm_dir,'tracts_pico_gm_1cm_acm_sc.nii.gz'));
ni_fiber_gm_exit = niftiRead(fullfile(camino_dir,'tracts_mesd_gm_exit_1cm_ends.nii.gz'));
%ni_fiber_gm = niftiRead(fullfile(acm_dir,'tracts_pico_gm_1cm_acm_sc.nii.gz'));
num_gm_exit_vox = sum(ni_fiber_gm_exit.data(:)>fiber_cthresh & ni_gm.data(:)>0);
ecc_exit_vox = ni_ecc.data(ni_fiber_gm_exit.data>fiber_cthresh & ni_ecc.data>0);
num_ret_exit_vox = numel(ecc_exit_vox);
Expand Down Expand Up @@ -75,8 +75,8 @@
dtiWriteNiftiWrapper(fdImg, xform_img_to_acpc, fullfile(tract_dir,[file_root '.nii.gz']));

% Some voxel comparisons
ni_a = readFileNifti(fullfile(camino_dir,'tracts_pico_gm_1cm_ends.nii.gz'));
ni_e = readFileNifti(fullfile(camino_dir,'tracts_mesd_gm_exit_1cm_ends.nii.gz'));
ni_a = niftiRead(fullfile(camino_dir,'tracts_pico_gm_1cm_ends.nii.gz'));
ni_e = niftiRead(fullfile(camino_dir,'tracts_mesd_gm_exit_1cm_ends.nii.gz'));
a_vox = ni_a.data(ni_a.data>0);
e_vox = ni_e.data(ni_a.data>0);
figure, plot(a_vox,e_vox,'.');
Expand Down
46 changes: 23 additions & 23 deletions external/camino/s_cam_generate_tracking_masks.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
end

%% Load all reinterpolated data
ni_seg = readFileNifti(fullfile(mask_dir,seg_filename));
ni_var = readFileNifti(fullfile(mask_dir,var_map_filename));
ni_ecc = readFileNifti(fullfile(mask_dir,ecc_map_filename));
ni_rois = readFileNifti(fullfile(mask_dir,roi_map_filename));
ni_seg = niftiRead(fullfile(mask_dir,seg_filename));
ni_var = niftiRead(fullfile(mask_dir,var_map_filename));
ni_ecc = niftiRead(fullfile(mask_dir,ecc_map_filename));
ni_rois = niftiRead(fullfile(mask_dir,roi_map_filename));

%% Gray Matter Mask
% RH
Expand Down Expand Up @@ -102,7 +102,7 @@
% RH
ni_occ = ni_seg;
ni_occ.fname = fullfile(mask_dir,'occ_rh_mask.nii.gz');
ni_gm = readFileNifti(fullfile(mask_dir,'gm_rh.nii.gz'));
ni_gm = niftiRead(fullfile(mask_dir,'gm_rh.nii.gz'));
% Grab only right hemisphere GM and WM
ni_occ.data(ni_seg.data~=6 & ni_seg.data~=4) = 0;
ni_occ.data(ni_occ.data>0) = 1;
Expand All @@ -116,7 +116,7 @@
% LH
ni_occ = ni_seg;
ni_occ.fname = fullfile(mask_dir,'occ_lh_mask.nii.gz');
ni_gm = readFileNifti(fullfile(mask_dir,'gm_lh.nii.gz'));
ni_gm = niftiRead(fullfile(mask_dir,'gm_lh.nii.gz'));
% Grab only left hemisphere GM and WM
ni_occ.data(ni_seg.data~=5 & ni_seg.data~=3) = 0;
ni_occ.data(ni_occ.data>0) = 1;
Expand All @@ -128,32 +128,32 @@
writeFileNifti(ni_occ);

%% Create a background mask in native diffusion space
%ni_b0 = readFileNifti(fullfile(dti_dir,b0_filename));
%ni_b0 = niftiRead(fullfile(dti_dir,b0_filename));
%lowres_pixdim = ni_b0.pixdim;
%camAlignImageToDTI( fullfile(dti_dir,b0_filename), fullfile(mask_dir,'occ_rh_mask.nii.gz'), fullfile(mask_dir,'bgmask_rh.nii.gz'), lowres_pixdim);
%camAlignImageToDTI( fullfile(dti_dir,b0_filename), fullfile(mask_dir,'occ_lh_mask.nii.gz'), fullfile(mask_dir,'bgmask_lh.nii.gz'), lowres_pixdim);

%% Define outside occ lobe for exclusion purposes
% RH
ni_occ = readFileNifti( fullfile(mask_dir,'occ_rh_mask.nii.gz') );
ni_not_occ = readFileNifti(fullfile(mask_dir,'occ_rh_mask.nii.gz'));
ni_occ = niftiRead( fullfile(mask_dir,'occ_rh_mask.nii.gz') );
ni_not_occ = niftiRead(fullfile(mask_dir,'occ_rh_mask.nii.gz'));
ni_not_occ.fname = fullfile(mask_dir,'not_occ_rh_mask.nii.gz');
ni_not_occ.data(ni_occ.data==0) = 1;
ni_not_occ.data(ni_occ.data==1) = 0;
writeFileNifti(ni_not_occ);
% LH
ni_occ = readFileNifti( fullfile(mask_dir,'occ_lh_mask.nii.gz') );
ni_not_occ = readFileNifti(fullfile(mask_dir,'occ_lh_mask.nii.gz'));
ni_occ = niftiRead( fullfile(mask_dir,'occ_lh_mask.nii.gz') );
ni_not_occ = niftiRead(fullfile(mask_dir,'occ_lh_mask.nii.gz'));
ni_not_occ.fname = fullfile(mask_dir,'not_occ_lh_mask.nii.gz');
ni_not_occ.data(ni_occ.data==0) = 1;
ni_not_occ.data(ni_occ.data==1) = 0;
writeFileNifti(ni_not_occ);

%% Image that defines the occipital exit plane and GM as two ROIs
% RH
ni_occ_exit = readFileNifti(fullfile(mask_dir,'wm_rh_exit.nii.gz'));
ni_occ_exit = niftiRead(fullfile(mask_dir,'wm_rh_exit.nii.gz'));
ni_occ_exit.fname = fullfile(mask_dir,'occ_rh_exit.nii.gz');
ni_gm = readFileNifti(fullfile(mask_dir,'gm_rh.nii.gz'));
ni_gm = niftiRead(fullfile(mask_dir,'gm_rh.nii.gz'));
ni_occ_exit.data(ni_gm.data>0) = 2;
writeFileNifti(ni_occ_exit);
% Now the mask
Expand All @@ -163,9 +163,9 @@
writeFileNifti(ni_occ_exit_mask);

% LH
ni_occ_exit = readFileNifti(fullfile(mask_dir,'wm_lh_exit.nii.gz'));
ni_occ_exit = niftiRead(fullfile(mask_dir,'wm_lh_exit.nii.gz'));
ni_occ_exit.fname = fullfile(mask_dir,'occ_lh_exit.nii.gz');
ni_gm = readFileNifti(fullfile(mask_dir,'gm_lh.nii.gz'));
ni_gm = niftiRead(fullfile(mask_dir,'gm_lh.nii.gz'));
ni_occ_exit.data(ni_gm.data>0) = 2;
writeFileNifti(ni_occ_exit);
% Now the mask
Expand Down Expand Up @@ -208,7 +208,7 @@
% Ecc Ventral
var = 0.2;
filename = fullfile(mask_dir,sprintf('atlas_%s_%s_%.2f.nii.gz',ecc_atlas_root,var_atlas_root,var));
ecc = readFileNifti(filename);
ecc = niftiRead(filename);
ecc.data(data==0) = 0;
filename = fullfile(mask_dir,sprintf('atlas_%s_%s_%s_%.2f.nii.gz',roi_ventral_atlas_root,ecc_atlas_root,var_atlas_root,var));
dtiWriteNiftiWrapper(ecc.data,ecc.qto_xyz,filename);
Expand All @@ -229,7 +229,7 @@
% Ecc Dorsal
var = 0.2;
filename = fullfile(mask_dir,sprintf('atlas_%s_%s_%.2f.nii.gz',ecc_atlas_root,var_atlas_root,var));
ecc = readFileNifti(filename);
ecc = niftiRead(filename);
ecc.data(data==0) = 0;
filename = fullfile(mask_dir,sprintf('atlas_%s_%s_%s_%.2f.nii.gz',roi_dorsal_atlas_root,ecc_atlas_root,var_atlas_root,var));
dtiWriteNiftiWrapper(ecc.data,ecc.qto_xyz,filename);
Expand All @@ -246,7 +246,7 @@
filename = fullfile(mask_dir,sprintf('atlas_%s_%s_%.2f.nii.gz',ecc_atlas_root,var_atlas_root,var));
% C1 ECC
var = 0.2;
ecc = readFileNifti(filename);
ecc = niftiRead(filename);
ecc.data(data==0) = 0;
filename = fullfile(mask_dir,sprintf('atlas_%s_%s_%s_%.2f.nii.gz',roi_c1_atlas_root,ecc_atlas_root,var_atlas_root,var));
dtiWriteNiftiWrapper(ecc.data,ecc.qto_xyz,filename);
Expand All @@ -261,7 +261,7 @@
filename = fullfile(mask_dir,sprintf('atlas_%s_%s_%.2f.nii.gz',ecc_atlas_root,var_atlas_root,var));
% CMT ECC
var = 0.2;
ecc = readFileNifti(filename);
ecc = niftiRead(filename);
ecc.data(data==0) = 0;
filename = fullfile(mask_dir,sprintf('atlas_%s_%s_%s_%.2f.nii.gz',roi_cmt_atlas_root,ecc_atlas_root,var_atlas_root,var));
dtiWriteNiftiWrapper(ecc.data,ecc.qto_xyz,filename);
Expand All @@ -276,7 +276,7 @@
filename = fullfile(mask_dir,sprintf('atlas_%s_%s_%.2f.nii.gz',ecc_atlas_root,var_atlas_root,var));
% CVO ECC
var = 0.2;
ecc = readFileNifti(filename);
ecc = niftiRead(filename);
ecc.data(data==0) = 0;
filename = fullfile(mask_dir,sprintf('atlas_%s_%s_%s_%.2f.nii.gz',roi_cvo_atlas_root,ecc_atlas_root,var_atlas_root,var));
dtiWriteNiftiWrapper(ecc.data,ecc.qto_xyz,filename);
Expand All @@ -291,7 +291,7 @@
filename = fullfile(mask_dir,sprintf('atlas_%s_%s_%.2f.nii.gz',ecc_atlas_root,var_atlas_root,var));
% cv3ab ECC
var = 0.2;
ecc = readFileNifti(filename);
ecc = niftiRead(filename);
ecc.data(data==0) = 0;
filename = fullfile(mask_dir,sprintf('atlas_%s_%s_%s_%.2f.nii.gz',roi_cv3ab_atlas_root,ecc_atlas_root,var_atlas_root,var));
dtiWriteNiftiWrapper(ecc.data,ecc.qto_xyz,filename);
Expand All @@ -305,13 +305,13 @@
hem = hem_names{hh};
% Load exit wm
filename = fullfile(mask_dir,sprintf('wm_%s_exit.nii.gz',hem));
ni = readFileNifti(filename);
ni = niftiRead(filename);
num_vox_exit = sum(ni.data(:)>0);
% Go through each variance explained level
for vv = 1:length(var_thresh)
var = var_thresh(vv);
filename = fullfile(mask_dir,sprintf('%s_%s_%d_%s_%.2f_%s.nii.gz',cbs_root,hem,num_tracks,var_atlas_root,var,lbl_post));
ni = readFileNifti(filename);
ni = niftiRead(filename);
exit_data(hh,vv) = sum(ni.data(:)>0) / num_vox_exit;
end
end
Expand Down
32 changes: 16 additions & 16 deletions external/camino/s_cam_notes.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
s_cam_definitions;

%% Load image for pathway xforms
ni_seg = readFileNifti(fullfile(mask_dir,seg_filename));
ni_seg = niftiRead(fullfile(mask_dir,seg_filename));
% Calc xform from camino space to acpc space
xform = ni_seg.qto_xyz;
xform(1:3,1:3) = eye(3);
Expand All @@ -14,7 +14,7 @@
%% Fix image header
%filename = fullfile(camino_dir,'acm','t_mesd_gm_rh_exit_1cm_acm_sc.nii.gz');
filename = fullfile(camino_dir,'fa.nii.gz');
ni = readFileNifti(filename);
ni = niftiRead(filename);
dtiWriteNiftiWrapper(ni.data, xform_img_to_acpc, filename);

%% Load generated paths
Expand All @@ -36,14 +36,14 @@
dtiWriteNiftiWrapper(fd_img, xform_img_to_acpc, fullfile(camino_dir,'tracts_occ.nii.gz'));
% Intersect occ map with cortex
tracts_filename = 'tracts_occ.nii.gz';
ni_tracts = readFileNifti(fullfile(camino_dir, tracts_filename));
ni_c = readFileNifti(fullfile(mask_dir,'gm.nii.gz'));
ni_tracts = niftiRead(fullfile(camino_dir, tracts_filename));
ni_c = niftiRead(fullfile(mask_dir,'gm.nii.gz'));
ni_tracts.fname = fullfile(camino_dir,'tracts_occ_gm.nii.gz');
ni_tracts.data(ni_c.data==0) = 0;
writeFileNifti(ni_tracts);
% Intersect with retinotopic cortex
ni_tracts = readFileNifti(fullfile(camino_dir, tracts_filename));
ni_c = readFileNifti(fullfile(mask_dir,'atlas_mask.nii.gz'));
ni_tracts = niftiRead(fullfile(camino_dir, tracts_filename));
ni_c = niftiRead(fullfile(mask_dir,'atlas_mask.nii.gz'));
ni_tracts.fname = fullfile(camino_dir,'tracts_occ_atlas.nii.gz');
ni_tracts.data(ni_c.data==0) = 0;
writeFileNifti(ni_tracts);
Expand All @@ -58,31 +58,31 @@
dtiWriteNiftiWrapper(fd_img, xform_img_to_acpc, fullfile(camino_dir,'tracts_occ_exit.nii.gz'));
% Intersect occ map with cortex
tracts_filename = 'tracts_occ_exit.nii.gz';
ni_tracts = readFileNifti(fullfile(camino_dir, tracts_filename));
ni_c = readFileNifti(fullfile(mask_dir,'gm.nii.gz'));
ni_tracts = niftiRead(fullfile(camino_dir, tracts_filename));
ni_c = niftiRead(fullfile(mask_dir,'gm.nii.gz'));
ni_tracts.fname = fullfile(camino_dir,'tracts_occ_exit_gm.nii.gz');
ni_tracts.data(ni_c.data==0) = 0;
writeFileNifti(ni_tracts);
% Intersect with retinotopic cortex
ni_tracts = readFileNifti(fullfile(camino_dir, tracts_filename));
ni_c = readFileNifti(fullfile(mask_dir,'atlas_mask.nii.gz'));
ni_tracts = niftiRead(fullfile(camino_dir, tracts_filename));
ni_c = niftiRead(fullfile(mask_dir,'atlas_mask.nii.gz'));
ni_tracts.fname = fullfile(camino_dir,'tracts_occ_exit_atlas.nii.gz');
ni_tracts.data(ni_c.data==0) = 0;
writeFileNifti(ni_tracts);

%% Tract surface measurements

%% Fix residual image
ni_b0 = readFileNifti(fullfile(dti_dir,'b0.nii.gz'));
ni = readFileNifti(fullfile(camino_dir,'wdt_rmsqr.nii.gz'));
ni_b0 = niftiRead(fullfile(dti_dir,'b0.nii.gz'));
ni = niftiRead(fullfile(camino_dir,'wdt_rmsqr.nii.gz'));
ni_b0.fname = fullfile(camino_dir,'wdt_rmsqr.nii.gz');
ni_b0.data = ni.data;
%ni_b0.data = ni.data(1:-1:end,:,:);
writeFileNifti(ni_b0);

%% Examine residuals
ni_mse = readFileNifti(fullfile(camino_dir,'wdt_rmsqr.nii.gz'));
ni_std = readFileNifti(fullfile(camino_dir,'wdt_std.nii.gz'));
ni_mse = niftiRead(fullfile(camino_dir,'wdt_rmsqr.nii.gz'));
ni_std = niftiRead(fullfile(camino_dir,'wdt_std.nii.gz'));
ni_std.data(ni_std.data>100) = 100;
ni_mse.data(ni_mse.data>100) = 100;
showMontage(ni_std.data)
Expand All @@ -93,14 +93,14 @@

% Fix label image
filename_labels = fullfile(camino_dir,'cbs_labels_1_1_0.nii.gz');
ni = readFileNifti(filename_labels);
ni = niftiRead(filename_labels);
ni_labels = ni_occ;
ni_labels.fname = filename_labels;
ni_labels.data = ni.data;
writeFileNifti(ni_labels);

filename_labels = fullfile(camino_dir,'cbs_labelcp_1_1_0.nii.gz');
ni = readFileNifti(filename_labels);
ni = niftiRead(filename_labels);
ni_labels = ni_occ;
ni_labels.fname = filename_labels;
ni_labels.data = ni.data;
Expand Down
Loading

0 comments on commit f9eaa12

Please sign in to comment.