Exemplo n.º 1
0
def muti_bundle_registration(paths_file, pts=12):
    """
    muti-bundle registration and consolidation
    Parameters
    ----------
    paths_file: list; muti_bundle file path
    pts: each streamline is divided into sections

    Return
    ------
    new header: include id of each streamline that comes from different subjects
    registration and consolidation bundle
    """
    fas = Fasciculus(paths_file[0])
    # print fas.get_header()
    bundle_header = {'fasciculus_id': None}
    sub1 = fas.get_data()
    bundle_header['fasciculus_id'] = len(sub1) * [
        int(paths_file[0].split('/')[9])
    ]
    sub2 = Fasciculus(paths_file[1]).get_data()
    subj2_aligned = bundle_registration(sub1, sub2, pts=pts)
    bundle = fas.fib_merge(sub1, subj2_aligned)
    bundle_header['fasciculus_id'] += (
        len(bundle) - len(sub1)) * [int(paths_file[1].split('/')[9])]
    # print bundle_header
    # print len(bundle)
    for index in range(len(paths_file))[2:]:
        # print paths_file[index]
        sub = Fasciculus(paths_file[index]).get_data()
        sub_aligned = bundle_registration(sub1, sub, pts=pts)
        lenth = len(bundle)
        bundle = fas.fib_merge(bundle, sub_aligned)
        bundle_header['fasciculus_id'] += (
            len(bundle) - lenth) * [int(paths_file[index].split('/')[9])]

    fas.update_header(bundle_header)
    fas.set_data(nibas.ArraySequence(bundle))

    return fas
Exemplo n.º 2
0

fib = '/home/brain/workingdir/data/dwi/hcp/preprocessed/' \
      'response_dhollander/101107/Diffusion/1M_20_01_20dynamic250_SD_Stream_rhemi_occipital5.tck'
# fib = '/home/brain/workingdir/data/dwi/hcp/preprocessed/' \
#            'response_dhollander/101107/Diffusion/1M_20_01_20dynamic250_SD_Stream_occipital8_lr5.tck'
img_path = '/home/brain/workingdir/data/dwi/hcp/preprocessed/' \
           'response_dhollander/101107/Structure/T1w_acpc_dc_restore_brain1.25.nii.gz'

img = nib.load(img_path)
fa = Fasciculus(fib)
streamlines = fa.get_data()
length_t = fa.get_lengths()
ind = length_t > 10
streamlines = streamlines[ind]
fa.set_data(streamlines)
fibcluster = FibClustering(fa)
print len(streamlines)

# 1
qb = QuickBundles(streamlines, 2)
clusters = qb.clusters()
print qb.clusters_sizes()
indexs = []
for i in range(len(clusters)):
    if clusters[i]['N'] >= 400:
        indexs += clusters[i]['indices']

# 2
streamlines = streamlines[indexs]
qb = QuickBundles(streamlines, 2)
Exemplo n.º 3
0
l_labels = '/home/brain/workingdir/data/dwi/hcp/preprocessed/' \
           'response_dhollander/100408/my_labels/native/native_lh_VMV3.label'
r_labels = '/home/brain/workingdir/data/dwi/hcp/preprocessed/' \
           'response_dhollander/100408/my_labels/native/native_rh_VMV3.label'

lr_labels_vir_name = 'native_lrh_VMV3'
lr_labels_path = [l_labels, r_labels]
labels_values = label2surf_roi(lr_labels_path, geo_path)

# surface_streamlines_map(subjects_dir, subject_id, hemi, surf, alpha, labels_values)

#
# surface_roi_contour(subjects_dir, subject_id, hemi, surf, alpha, lr_label, lr_label)
streams = select_by_surf_rois(streamlines, labels_values, geo_path)
suffix = []
for i in range(len(lr_labels_path)):
    suffix.append(os.path.split(lr_labels_path[i])[1].split('.')[-2])
if len(streams) == 3:
    suffix.append(lr_labels_vir_name)
#
# print suffix
#
out_path = '/home/brain/workingdir/data/dwi/hcp/preprocessed/' \
           'response_dhollander/100408/result/ROIs_fibs/hcp_VanEssen_Atlas/VMV3/%s_fib_SD_stream.tck'
for j in range(len(streams)):
    fasciculus.set_data(streams[j])
    fasciculus.save2tck(out_path % suffix[j])

# for i in range(len(streams)):
#     fiber_simple_3d_show_advanced(img, streams[i], 1)
Exemplo n.º 4
0
def cc_seg_pipeline(tck_path, mask, geo_path, thr=5., roi_id=None, step=0):
    """
    Extract occipital streamlines and separate hemisphere streamlines
    Parameters
    ----------
    tck_path: list; streamline file path (.tck)
    mask: surface mask (xh.aparc.annot)
    geo_path: geometry data path (subject_id.L.white.native.surf.gii)
    thr: distance of streamline terminus to surface

    Return
    ------
    occipital streamlines
    """
    # load data
    fasciculus = Fasciculus(tck_path)

    # extract streamlines from left to right hemisphere
    fibselection = FibSelection(fasciculus)
    L_temp_need0 = fibselection.endpoint_dissimilarity()
    fasciculus.set_data(L_temp_need0)
    L_temp_need1 = fibselection.single_point_mid_sag()
    fasciculus.set_data(L_temp_need1)
    del L_temp_need0, L_temp_need1
    gc.collect()

    # separation of lr_seed fib
    fib = fasciculus.hemi_fib_separation()

    # choose the mask: Occipital
    mask_fib = []
    for i in range(len(fib)):
        vertices, colortable, label = nib.freesurfer.read_annot(mask[i])
        gii_data = nib.load(geo_path[i]).darrays
        coords, faces = gii_data[0].data, gii_data[1].data

        label_value = np.array(len(coords) * [0])
        if not roi_id:
            label_value[vertices == 11] = 11  # lateraloccipital
            label_value[vertices == 13] = 13  # lingual
            label_value[vertices == 5] = 5  # cuneus
            label_value[vertices == 21] = 21  # pericalcarine
        else:
            for value in roi_id:
                label_value[vertices == value] = value

        # extract fib using mask
        streamlines = fib[i]
        streamlines = fasciculus.sort_streamlines(streamlines)

        if i == 0:
            s0 = [s[0] for s in streamlines]
        else:
            s0 = [s[-1] for s in streamlines]

        stream_terminus = np.array(s0)
        dist = cdist(coords[label_value > 0], stream_terminus)
        stream_index = np.array(len(streamlines) * [False])
        for j in range(len(dist[:])):
            temp_index = np.array(dist[j] <= thr)
            stream_index += temp_index

        rois_streamlines = streamlines[stream_index]
        mask_fib.append(rois_streamlines)

    # lr fib merge
    fib_merge = fasciculus.fib_merge(mask_fib[0], mask_fib[1])
    del mask_fib
    gc.collect()
    fib_hemi = fasciculus.separation_fib_to_hemi(fib_merge)
    del fib_merge
    gc.collect()

    return fib_hemi
Exemplo n.º 5
0
# !/usr/bin/python
# -*- coding: utf-8 -*-

from pyfat.core.dataobject import Fasciculus
from pyfat.algorithm.fiber_extract import FibSelection
# load data
# file = '/home/brain/workingdir/data/dwi/hcp/preprocessed/' \
#        'response_dhollander/100206/Diffusion/100k_sift_1M45006_dynamic250.tck'
file = '/home/brain/workingdir/data/dwi/hcp/preprocessed/' \
       'response_dhollander/100408/result/result20vs45/Prob01_plenium_fib_vis.tck'
fasciculus = Fasciculus(file)

# extract CC
fibselection = FibSelection(fasciculus)
L_temp_need0 = fibselection.endpoint_dissimilarity()
fasciculus.set_data(L_temp_need0)
L_temp_need1 = fibselection.single_point_mid_sag()
fasciculus.set_data(L_temp_need1)
L_temp_need2 = fibselection.lr_step()
fasciculus.set_data(L_temp_need2)

out_path = '/home/brain/workingdir/data/dwi/hcp/preprocessed/' \
           'response_dhollander/100408/result/result20vs45/Prob01_plenium_fib_vis_pure.tck'
fasciculus.save2tck(out_path)

# if __name__ == '__main__':
#     fib_path = '/home/brain/workingdir/data/dwi/hcp/preprocessed/' \
#                'response_dhollander/100408/result/result20vs45/Prob01_plenium_fib.tck'
#     out_path = '/home/brain/workingdir/data/dwi/hcp/preprocessed/' \
#                'response_dhollander/100408/result/result20vs45/Prob01_plenium_fib_vis.tck'
#     fasciculus = Fasciculus(fib_path)
Exemplo n.º 6
0
# !/usr/bin/python
# -*- coding: utf-8 -*-

from pyfat.io.load import load_tck
from pyfat.core.dataobject import Fasciculus
from pyfat.algorithm.fiber_extract import FibSelection


source_path = '/home/brain/workingdir/data/dwi/hcp/preprocessed/' \
              'response_dhollander/101107/Diffusion/1M_20_01_20dynamic250_SD_Stream_rh_occipital8.tck'

fasciculus = Fasciculus(source_path)
fibs = FibSelection(fasciculus)
fib = fibs.lr_rat(5)
fasciculus.set_data(fib)
out_path = '/home/brain/workingdir/data/dwi/hcp/preprocessed/' \
              'response_dhollander/101107/Diffusion/1M_20_01_20dynamic250_SD_Stream_rh_occipital8_lr5.tck'
fasciculus.save2tck(out_path)


Exemplo n.º 7
0
# subjects_dir = "/home/brain/workingdir/data/dwi/hcp/preprocessed/response_dhollander/101107"
# hemi = 'lh'
# surf = 'white'
# alpha = 1
# brain = Brain(subjects_dir=subjects_dir, subject_id=subject_id, hemi=hemi, surf=surf, alpha=alpha)
# brain.add_overlay(l_label_value, min=l_label_value[l_label_value > 0].min(),
#                   max=l_label_value.max(), sign='pos', hemi='lh', name='lh')
#
# mlab.show()

tck_path = '/home/brain/workingdir/data/dwi/hcp/preprocessed/' \
           'response_dhollander/101107/Diffusion/1M_20_01_20dynamic250_SD_Stream_single.tck'

fasciculus = Fasciculus(tck_path)
streamlines = fasciculus.get_data()
print len(streamlines)
streamlines = fasciculus.sort_streamlines()
s0 = [s[0] for s in streamlines]
stream_terminus_lh = np.array(s0)
dist_lh = cdist(coords[l_label_value > 0], stream_terminus_lh)
lh_stream_index = np.array(len(streamlines) * [False])
for i in range(len(dist_lh[:])):
    temp_index = np.array(dist_lh[i] <= 3)
    lh_stream_index += temp_index

lh_rois_streamlines = streamlines[lh_stream_index]
fasciculus.set_data(lh_rois_streamlines)
out_path = '/home/brain/workingdir/data/dwi/hcp/preprocessed/' \
           'response_dhollander/101107/Diffusion/1M_20_01_20dynamic250_SD_Stream_lh_occipital3.tck'
fasciculus.save2tck(out_path)