#Right #s_cst_ext_file = '/home/bao/tiensy/Lauren_registration/data_compare_mapping/pairwise_reg_cstext2cstext/CST_ROI_trkvis_Right/' + source_sub + '_' + target_sub + '/out_reg/iteration_4/' + source_sub + '_cst_R_tvis_ext_reg.trk' #t_cst_ext_file = '/home/bao/tiensy/Lauren_registration/data_compare_mapping/pairwise_reg_cstext2cstext/CST_ROI_trkvis_Right/' + source_sub + '_' + target_sub + '/out_reg/iteration_4/' + target_sub + '_cst_R_tvis_ext_reg.trk' #out_file = '/home/bao/tiensy/Tractography_Mapping/data/trackvis_tractography/Lauren_pair_CSText2CSText/Lauren_pair_CSText2CSText_f300_l75_1NN/map_1nn_pairwise_reg_CST_R_ext_' + source_sub + '_aligned_to_CST_R_ext_' + target_sub + '_Lauren_f300_l75.txt' s_cst_ext_file = '/home/bao/tiensy/Lauren_registration/data_compare_mapping/pairwise_reg_cstext2cstext/CST_ROI_trkvis_Right/' + source_sub + '_' + target_sub + '/out_reg_f100_l25/iteration_4/' + source_sub + '_cst_R_tvis_ext_reg.trk' t_cst_ext_file = '/home/bao/tiensy/Lauren_registration/data_compare_mapping/pairwise_reg_cstext2cstext/CST_ROI_trkvis_Right/' + source_sub + '_' + target_sub + '/out_reg_f100_l25/iteration_4/' + target_sub + '_cst_R_tvis_ext_reg.trk' out_file = '/home/bao/tiensy/Tractography_Mapping/data/trackvis_tractography/Lauren_pair_CSText2CSText/Lauren_pair_CSText2CSText_f100_l25_1NN/map_1nn_pairwise_reg_CST_R_ext_' + source_sub + '_aligned_to_CST_R_ext_' + target_sub + '_Lauren_f100_l25.txt' s_cst_idx_file = '/home/bao/tiensy/Tractography_Mapping/data/trackvis_tractography/ROI_seg_tvis/ROI_seg_tvis_native/' + source_sub + '_corticospinal_R_tvis.pkl' t_cst_idx_file = '/home/bao/tiensy/Tractography_Mapping/data/trackvis_tractography/ROI_seg_tvis/ROI_seg_tvis_native/' + target_sub + '_corticospinal_R_tvis.pkl' ''' source_ext = load_whole_tract(s_cst_ext_file) target_ext = load_whole_tract(t_cst_ext_file) s_cst_idx = load_pickle(s_cst_idx_file) source = source_ext[:len(s_cst_idx)] t_cst_idx = load_pickle(t_cst_idx_file) target = target_ext[:len(t_cst_idx)] #print len(source), len(target) tractography1 = source tractography2 = target_ext map_all = mapping_nn(tractography1, tractography2)
ROIs = ROIs_subject[source] #convert from LPS in TrackVis software to LAS in dpy format ROIs = [[r[0],128.-r[1],r[2]] for r in ROIs] ''' ''' #trackvis tractography native space tracks_ind_file = '/home/bao/tiensy/Tractography_Mapping/data/trackvis_tractography/ROI_seg_tvis_native/' + source + '_corticospinal_R_tvis_native.pkl' tract_file = '/home/bao/tiensy/Tractography_Mapping/data/trackvis_tractography/' + source + '_tracks_dti_tvis.trk' tracks = load_whole_tract_trk(tract_file) ''' #trackvis tractography-MNI space ROI segmentation tract_file = '/home/bao/tiensy/Tractography_Mapping/data/trackvis_tractography/tvis_tractography/' + source + '_tracks_dti_tvis_linear.dpy' tracks = load_whole_tract(tract_file) from intersect_roi import * ROIs = ROIs_subject[source] print ROIs #common = intersec_ROIs_dpy(tracks, ROIs, Rs, vis = True) common = intersec_ROIs(tracks, ROIs, Rs, vis = True) print "\t Total ", len(tracks), " and the number of fibers cross the ROIs ", len(common) tracks_ind_file = '/home/bao/tiensy/Tractography_Mapping/data/trackvis_tractography/ROI_seg_tvis_MNI/' + source + '_corticospinal_L_tvis_MNI.pkl' save_pickle(tracks_ind_file, common) print "Saved file", tracks_ind_file
vis = False save = True for s_id in np.arange(len(source_ids)): print '-----------------------------------------------------------------------------------------' print 'Source: ', source_ids[s_id] source = str(source_ids[s_id]) flirt_filename = '/home/bao/Personal/PhD_at_Trento/Research/ALS_Nivedita_Bao/Code/data/' + source+'/DIFF2DEPI_EKJ_64dirs_14/DTI/flirt.mat' fa_filename= '/home/bao/Personal/PhD_at_Trento/Research/ALS_Nivedita_Bao/Segmentation_CST_francesca/' + source + '/DTI/dti_fa_brain.nii.gz' tracks_filename = '/home/bao/Personal/PhD_at_Trento/Research/ALS_Nivedita_Bao/Segmentation_CST_francesca/' + source + '/DTI/dti.trk' linear_filename = '/home/bao/Personal/PhD_at_Trento/Research/ALS_Nivedita_Bao/Segmentation_CST_francesca/' + source + '/DTI/dti_linear.dpy' warp_tracks_linearly(flirt_filename,fa_filename, tracks_filename,linear_filename) print 'Saved ', linear_filename tract_linear = load_whole_tract(linear_filename) if save: from common_functions import save_tract_trk fa_warped = '/home/bao/Personal/PhD_at_Trento/Research/ALS_Nivedita_Bao/Code/data/' + source+'/DIFF2DEPI_EKJ_64dirs_14/DTI/fa_warped.nii.gz' fname_out = '/home/bao/Personal/PhD_at_Trento/Research/ALS_Nivedita_Bao/Segmentation_CST_francesca/' + source + '/DTI/dti_linear.trk' save_tract_trk(tract_linear, fa_warped, fname_out ) print 'Saved ', fname_out if vis: tract = load_whole_tract(tracks_filename) from dipy.viz import fvtk from common_functions import visualize_tract ren = fvtk.ren() visualize_tract(ren, tract,color=fvtk.red) visualize_tract(ren, tract_linear,color=fvtk.blue) fvtk.show(ren)
''' #Right s_cst_ext_file = '/home/nilab/tiensy/Tractography_Mapping/data/trackvis_tractography/Elef_pair_CSText2CSText/CST_R_ext_' + source_sub + '_aligned_to_CST_R_ext_' + target_sub + '_elef_rand_50_fiberpoint_40.dpy' out_file = '/home/nilab/tiensy/Tractography_Mapping/data/trackvis_tractography/Elef_pair_CSText2CSText/Elef_pair_CSText2CSText_1NN/map_1nn_pairwise_reg_CST_R_ext_' + source_sub + '_aligned_to_CST_R_ext_' + target_sub + '_elef_rand_50_fiberpoint_40.txt' s_cst_idx_file = '/home/nilab/tiensy/Tractography_Mapping/data/trackvis_tractography/ROI_seg_tvis/ROI_seg_tvis_native/' + source_sub + '_corticospinal_R_tvis.pkl' t_file = '/home/nilab/tiensy/Tractography_Mapping/data/trackvis_tractography/tvis_tractography/' + target_sub + '_tracks_dti_tvis.trk' t_cst_idx_file = '/home/nilab/tiensy/Tractography_Mapping/data/trackvis_tractography/ROI_seg_tvis/ROI_seg_tvis_native/' + target_sub + '_corticospinal_R_tvis.pkl' t_cst_ext_idx_file = '/home/nilab/tiensy/Tractography_Mapping/data/trackvis_tractography/50_SFF_in_ext/ROI_seg_native/' + target_sub + '_cst_R_tvis_ext.pkl' ''' s_cst_idx = load_pickle(s_cst_idx_file) source_ext = load_whole_tract(s_cst_ext_file) source = source_ext[:len(s_cst_idx)] target = load_tract(t_file, t_cst_ext_idx_file) #print len(source), len(target) tractography1 = source tractography2 = target map_all = mapping_nn(tractography1, tractography2) if save: #print 'Saving 1-NN Eleftherios tract based method: ', out_file