def streams_to_connmat(filename, seeds_per_voxel=1, thr=[0.25, 0.5, 0.75]): streams, hdr = nib.trackvis.read(filename) streamlines = [s[0] for s in streams] # show_streamlines(streamlines, opacity=0.5) rois, affine = get_train_rois() mat, srois, ratio = connectivity_matrix(streamlines, rois) golden_mat = np.load('train_connmat.npy') lr = [] for i in range(1, 41): lr.append(np.sum(rois == i)) lr = seeds_per_voxel * np.array(lr, dtype='f8') mat /= lr mat += mat.T golden_mat += golden_mat.T conn_mats = [] diffs = [] for th in thr: conn_mat = mat > th conn_mats.append(conn_mat) diffs.append(np.sum(np.abs(conn_mat - golden_mat))) return mat, conn_mats, diffs, ratio
opacity=opacity) fvtk.add(ren, line_actor) if r is None: fvtk.show(ren) else: return ren if __name__ == '__main__': from load_data import get_train_gt_fibers streamlines, radii = get_train_gt_fibers() show_gt_streamlines(streamlines, radii, 'orient', None) from load_data import get_train_rois rois, affine = get_train_rois() streamlines = [s + np.array([24.5, 24.5, 24.5]) for s in streamlines] from conn_mat import connectivity_matrix mat, srois, ratio = connectivity_matrix(streamlines, rois) np.save('train_connmat.npy', mat)