def modify_left_button_callback(i_ren, obj, button): print button.current_icon_id print button.current_icon_name if button.current_icon_id == 0: new_f = _computeFib(streamlines, sphereWidget) save_tck(new_f, header=fib.header, data_per_streamline=fib.tractogram.data_per_streamline, data_per_point=fib.tractogram.data_per_point, affine_to_rasmm=fib.tractogram.affine_to_rasmm, out_path=os.path.join(file_select_menu.current_directory, '%s.tck') % text.text) if button.current_icon_id == 1: pass button.next_icon() i_ren.force_render()
label_img = modularity_finetune[0] # choose fiber according to node clusters # index fig, ax = plt.subplots() slice = img.get_data()[img.shape[0] / 2, :, :] ax.imshow(slice.T, cmap='gray', origin='lower') color = plt.cm.spectral(np.linspace(0, 1, len(set(label_img)))) # save the fiber cluster out_path = '/home/brain/workingdir/data/dwi/hcp/' \ 'preprocessed/response_dhollander/100408/result/' \ 'result20vs45/cc_20fib_step20_new_correct_modularity_set0-1_%s.tck' for i in set(label_img): l = np.argwhere(label_img == i) stream = Ls_temp_labels == l stream_sum = stream.sum(axis=0) stream_temp = stream_sum > 0 fib_path_index = imgtck.streamlines[stream_temp] mid_node_affine = apply_affine(npl.inv(img.affine), Ls_temp[stream_temp]) ax.plot(np.array(mid_node_affine)[:, 1], np.array(mid_node_affine)[:, 2], 'o', color=color[i-1]) save_tck(fib_path_index, imgtck.header, imgtck.tractogram.data_per_streamline, imgtck.tractogram.data_per_point, imgtck.tractogram.affine_to_rasmm, out_path % i) plt.show()
L_temp_n.append(imgtck[i]) elif imgtck[i][j][0] == 0: if (j - 20) in range(len(imgtck[i])) \ and (j + 20) in range(len(imgtck[i])) \ and imgtck[i][j - 20][0] * imgtck[i][j + 20][0] < 0: L_temp_need.append(imgtck[i]) else: L_temp_n.append(imgtck[i]) return L_temp_need, L_temp_n if __name__ == '__main__': from pyfat.io.load import load_tck from pyfat.io.save import save_tck # load data file = '/home/brain/workingdir/data/dwi/hcp/preprocessed/' \ 'response_dhollander/100206/Diffusion/100k_sift_1M45006_dynamic250.tck' imgtck = load_tck(file) # extract CC L_temp = extract_multi_node(imgtck)[1] # print L_temp # save data out_path = '/home/brain/workingdir/data/dwi/hcp/' \ 'preprocessed/response_dhollander/100206/result/CC_multi_node_fib.tck' save_tck(L_temp, imgtck.header, imgtck.tractogram.data_per_streamline, imgtck.tractogram.data_per_point, imgtck.tractogram.affine_to_rasmm, out_path)
print len(labels) d = zip(labels, Ls_temp) L_temp_0 = nibAS.ArraySequence() L_temp_1 = nibAS.ArraySequence() L_temp_2 = nibAS.ArraySequence() L_temp_3 = nibAS.ArraySequence() for k in range(len(d)): if d[k][0] == 0: L_temp_0.append(img_cc.streamlines[k]) if d[k][0] == 1: L_temp_1.append(img_cc.streamlines[k]) if d[k][0] == 2: L_temp_2.append(img_cc.streamlines[k]) if d[k][0] == 3: L_temp_3.append(img_cc.streamlines[k]) out_put = '/home/brain/workingdir/data/dwi/hcp/preprocessed/response_dhollander/100206/result/CC_fib_only3_0.tck' out_put1 = '/home/brain/workingdir/data/dwi/hcp/preprocessed/response_dhollander/100206/result/CC_fib_only3_1.tck' out_put2 = '/home/brain/workingdir/data/dwi/hcp/preprocessed/response_dhollander/100206/result/CC_fib_only3_2.tck' out_put3 = '/home/brain/workingdir/data/dwi/hcp/preprocessed/response_dhollander/100206/result/CC_fib_only3_3.tck' save_tck(L_temp_0, img_cc.header, img_cc.tractogram.data_per_streamline, img_cc.tractogram.data_per_point, img_cc.tractogram.affine_to_rasmm, out_put) save_tck(L_temp_1, img_cc.header, img_cc.tractogram.data_per_streamline, img_cc.tractogram.data_per_point, img_cc.tractogram.affine_to_rasmm, out_put1) save_tck(L_temp_2, img_cc.header, img_cc.tractogram.data_per_streamline, img_cc.tractogram.data_per_point, img_cc.tractogram.affine_to_rasmm, out_put2) save_tck(L_temp_3, img_cc.header, img_cc.tractogram.data_per_streamline, img_cc.tractogram.data_per_point, img_cc.tractogram.affine_to_rasmm, out_put3)
L_temp2 = apply_affine(npl.inv(img.affine), L_temp2) L_temp3 = apply_affine(npl.inv(img.affine), L_temp3) ax.plot(np.array(L_temp0)[:, 1], np.array(L_temp0)[:, 2], 'o', color='r') ax.plot(np.array(L_temp1)[:, 1], np.array(L_temp1)[:, 2], 'o', color='b') ax.plot(np.array(L_temp2)[:, 1], np.array(L_temp2)[:, 2], 'o', color='g') ax.plot(np.array(L_temp3)[:, 1], np.array(L_temp3)[:, 2], 'o', color='c') plt.show() # save the fiber cluster out_path = '/home/brain/workingdir/data/dwi/hcp/' \ 'preprocessed/response_dhollander/100206/result/CC_fib_ncut_new_set0-1_0.tck' out_path1 = '/home/brain/workingdir/data/dwi/hcp/' \ 'preprocessed/response_dhollander/100206/result/CC_fib_ncut_new_set0-1_1.tck' out_path2 = '/home/brain/workingdir/data/dwi/hcp/' \ 'preprocessed/response_dhollander/100206/result/CC_fib_ncut_new_set0-1_2.tck' out_path3 = '/home/brain/workingdir/data/dwi/hcp/' \ 'preprocessed/response_dhollander/100206/result/CC_fib_ncut_new_set0-1_3.tck' save_tck(L_temp_0, imgtck.header, imgtck.tractogram.data_per_streamline, imgtck.tractogram.data_per_point, imgtck.tractogram.affine_to_rasmm, out_path) save_tck(L_temp_1, imgtck.header, imgtck.tractogram.data_per_streamline, imgtck.tractogram.data_per_point, imgtck.tractogram.affine_to_rasmm, out_path1) save_tck(L_temp_2, imgtck.header, imgtck.tractogram.data_per_streamline, imgtck.tractogram.data_per_point, imgtck.tractogram.affine_to_rasmm, out_path2) save_tck(L_temp_3, imgtck.header, imgtck.tractogram.data_per_streamline, imgtck.tractogram.data_per_point, imgtck.tractogram.affine_to_rasmm, out_path3)
other.append(f) fib_total.append(remain_fib_clusters[int(node_sort[0][0])]) fib_total.append(remain_fib_clusters[int(node_sort[1][0])]) if len(other) == 0: pass else: fib_total.append(other) fib_total.append(remain_fib_clusters[int(node_sort[-1][0])]) out_path = '/home/brain/workingdir/data/dwi/hcp/' \ 'preprocessed/response_dhollander/100408/result/' \ 'result20vs45/cc_20fib_lr1.5_01_new_hierarchical_single_%s.tck' spe_name_four = ['oc', 'ac', 'other', 'cc'] spe_name_three = ['oc', 'ac', 'cc'] for fi in range(len(fib_total)): if len(fib_total) == 4: save_tck(fib_total[fi], imgtck.header, imgtck.tractogram.data_per_streamline, imgtck.tractogram.data_per_point, imgtck.tractogram.affine_to_rasmm, out_path % spe_name_four[fi]) if len(fib_total) == 3: save_tck(fib_total[fi], imgtck.header, imgtck.tractogram.data_per_streamline, imgtck.tractogram.data_per_point, imgtck.tractogram.affine_to_rasmm, out_path % spe_name_three[fi]) plt.show()