Пример #1
0
def cc_seg_mp(vol_path, streamlines_path, labels):
    """
    Make probabilistic map (pm)
    Parameters
    ----------
    vol_path: volume (T1w) data path
    streamlimes_path: streamlines path
    labels: label of each streamline

    Return
    ------
    pm: probabilisic map
    """
    img = nib.load(vol_path)
    dim4 = (len(set(labels)),)
    cc_mp = np.zeros(img.shape + dim4, dtype=float)
    fasciculus = Fasciculus(streamlines_path)
    streamlines = fasciculus.get_data()
    fibs_points = apply_affine(npl.inv(img.affine), fasciculus.xmin_nodes()).astype(int)
    for i in range(len(streamlines)):
        index_i = fibs_points == np.array([fibs_points[i][0], fibs_points[i][1], fibs_points[i][2]])
        index_i = index_i.sum(axis=1)
        inddex = index_i == 3
        voxel_counts = np.sum(index_i == 3)
        dim4_value = []
        for label in set(labels):
            index_lab = labels == label
            arr = np.vstack((inddex, index_lab)).sum(axis=0)
            dim4_value.append(np.sum(arr == 2) / voxel_counts)
        cc_mp[fibs_points[i][0], fibs_points[i][1], fibs_points[i][2]] = dim4_value

    return cc_mp
Пример #2
0
# !/usr/bin/python
# -*- coding: utf-8 -*-

import nibabel as nib
from pyfat.io.load import load_tck
from pyfat.core.dataobject import Fasciculus
from pyfat.viz.visualization import show_slice_density

data_path = '/home/brain/workingdir/data/dwi/hcp/preprocessed/' \
                'response_dhollander/100408/Structure/T1w_short.nii.gz'
img = nib.load(data_path)

tck_path = '/home/brain/workingdir/data/dwi/hcp/preprocessed/' \
           'response_dhollander/100408/Diffusion/1M_20_002_dynamic250.tck'
fas = Fasciculus(tck_path)
Ls_temp = fas.xmin_nodes()
show_slice_density(img, Ls_temp)


Пример #3
0
data_path = '/home/brain/workingdir/data/dwi/hcp/preprocessed/' \
             'response_dhollander/100408/Structure/T1w_acpc_dc_restore_brain.nii.gz'
img = nib.load(data_path)
img_data = img.get_data()
# tck_path = '/home/brain/workingdir/data/dwi/hcp/preprocessed/' \
#        'response_dhollander/100408/result/result20vs45/cc_20fib_step20_new_sample5000.tck'
tck_path = '/home/brain/workingdir/data/dwi/hcp/preprocessed/' \
           'response_dhollander/100408/result/result20vs45/cc_20fib_lr1.5_01_new_correct.tck'

imgtck = load_tck(tck_path)
fasciculus = Fasciculus(tck_path)
streamstck = fasciculus.get_data()
# print streamstck

# extract node according to x-value
Ls_temp = fasciculus.xmin_nodes()
print len(Ls_temp)
# show node or density
# show_2d_node(img, Ls_temp)
# show_slice_density(img, Ls_temp)

# knn_graph = kneighbors_graph(Ls_temp, 10, include_self=False)
Ls_temp_labels, Ls_temp_centers = NodeClustering(Ls_temp).k_means()
sdist = pdist(Ls_temp_centers)
knn_graph = linkage(sdist, method='single', metric='euclidean')
print knn_graph

label_img = fcluster(knn_graph, t=2, criterion='distance')
print label_img

# choose fiber according to node clusters