Example #1
0
def normal_registration():
    target = read_ply('../data/132118/m_ex_atr-left_shore.ply')
    subject = read_ply('../data/150019/m_ex_atr-left_shore.ply')

    subject_after, _ = register(target, subject)

    draw_bundles([target, subject, subject_after],
                 [[1, 0, 0], [0, 0, 1], [0, 0, .7]])
Example #2
0
def left_to_right():
    target = read_ply('../data/132118/m_ex_atr-left_shore.ply')
    subject = read_ply('../data/132118/m_ex_atr-right_shore.ply')

    subject_after, _ = register(target, subject)

    draw_bundles([target, subject, subject_after],
                 [[1, 0, 0], [0, 0, 1], [0, 0, .7]])
Example #3
0
def fake_registration():
    mat = compose_matrix44([50, 20, 20, 180, 90, 90])
    target = read_ply('../data/132118/m_ex_atr-left_shore.ply')
    subject = transform_streamlines(moving, mat)

    subject_after_registration, _ = register(target, subject)

    draw_bundles([target, subject, subject_after_registration],
                 [[1, 0, 0], [0, 0, 1], [0, 0, .7]])
Example #4
0
def icp_registration():
    mat = compose_matrix44([50, 20, 20, 180, 90, 90, 5])
    subject = read_ply('../data/164939/m_ex_atr-left_shore.ply')
    #subject = read_ply('../data/150019/m_ex_atr-left_shore.ply')
    target = transform_streamlines(subject, mat)

    subject_T = pca_transform(target, subject)
    #subject_T=registration_icp(static=target,moving=subject,pca=True)
    draw_bundles([target, subject_T, subject],
                 [[1, 0, 0], [0, 0, 1], [0, 0, .7]])
Example #5
0
"""
from time import time

import numpy as np
from sklearn.neighbors import KDTree

import matplotlib.pyplot as plt

from dipy.tracking.streamline import transform_streamlines

from src.tractography.io import read_ply
from src.tractography.Utils import pca_transform_norm, flip
from src.tractography.registration import register
from src.tractography.viz import draw_bundles

static = read_ply('data/197348/m_ex_atr-left_shore.ply')
moving = read_ply('data/197348/m_ex_atr-right_shore.ply')
''' Apply PCA '''
pre_moving = pca_transform_norm(static, moving, best=True)
draw_bundles([pre_moving, static], [[0, 0, 1], [1, 0, 0]])
''' Flip '''
'''
pre_moving = flip(moving,x=-1)
draw_bundles([pre_moving,static],[[0,0,1],[1,0,0]])
'''

con_static = np.concatenate(static)
con_moving = np.concatenate(pre_moving)

start = time()
new_moving = register(static, pre_moving)
Example #6
0
    # plt.show()

    plt.hist(dist_before_PCA, bins='auto')
    plt.title("Distance before PCA (Moving is base)")
    plt.ylabel("Frequncy")
    plt.xlabel("Distance")
    plt.savefig('../pics/dist_before_PCA.png', dpi=600)
    plt.close()
    # plt.show()

    plt.hist(dist_after_PCA, bins='auto')
    plt.title("Distance After PCA (Moving is base) - distance < 20")
    plt.ylabel("Frequncy")
    plt.xlabel("Distance")
    plt.savefig('../pics/dist_after_PCA3.png', dpi=600)
    plt.close()
    # plt.show()

    costs = np.array(ut.costs) / 1000
    plt.plot(costs)
    plt.title("Cost valuse during optimization")
    plt.ylabel("Costs (k)")
    plt.xlabel("Number of evaluations")
    plt.savefig('pics/cost.png', dpi=600)
    plt.close()


static = read_ply('../data/132118/m_ex_atr-left_shore.ply')
moving = read_ply('../data/150019/m_ex_atr-right_shore.ply')
select_threshold(static, moving)
Example #7
0
@author: mabdelgadi
"""
import numpy as np

#import matplotlib.pyplot as plt

from sklearn.cluster import KMeans
from sklearn.neighbors import KDTree

from dipy.tracking.streamline import set_number_of_points

from src.tractography.viz import clusters_colors, draw_clusters, lines_colors
from src.tractography.io import read_ply

moving = read_ply('data/150019/m_ex_atr-left_shore.ply')

idx = [
    np.hstack(KDTree(j).query(i, k=1)[1])
    for i, j in zip(set_number_of_points(moving, 5), moving)
]

xyz = lines_colors(moving, [[1, 0, 0], [0, 1, 0], [0, 0, 1], [1, 0, 1]], idx)
print(xyz)

con_moving = np.concatenate(moving)
mov_cluster = KMeans(n_clusters=5).fit(con_moving)

mov_cluster = clusters_colors(
    moving, [[1, 0, 0], [0, 1, 0], [0, 0, 1], [1, 1, 0], [1, 0, 1]],
    mov_cluster.labels_)
Example #8
0
from src.tractography.io import read_ply

data_path = 'data/'

stat={}
max_bundles=0
min_bundles=sys.maxsize

max_points=0
min_points=sys.maxsize

for dirt in listdir(data_path):
    stat[dirt] = {}
    for bundle_path in listdir(data_path+dirt):
        bundle = read_ply(data_path+dirt+'/'+bundle_path)
        bundle_len = len(bundle)
        points_num = np.concatenate(bundle).shape[0]
        '''
        if bundle_len > max_bundles:
            max_bundles = bundle_len
        if bundle_len < min_bundles:
            min_bundles = bundle_len
            
        if points_num > max_points:
            max_points = points_num
        if points_num < min_points:
            min_points = points_num
        '''
        stat[dirt][bundle_path] = [bundle_len,points_num]
np.save('new_plan/bundles_statistic.npy',stat)
Example #9
0
from src.tractography.viz import draw_bundles
from os import listdir  # , mkdir
from os.path import isfile  # , isdir
from src.tractography.io import read_ply
import argparse
from dipy.align.streamlinear import compose_matrix44
from dipy.tracking.streamline import transform_streamlines

parser = argparse.ArgumentParser(description='Input argument parser.')
parser.add_argument('-f', type=str, help='location of files')
args = parser.parse_args()
data_path = '../data/132118/'
#data_path = args.f
files = [
    data_path + f for f in listdir(data_path)
    if isfile(data_path + f) and f.endswith('.ply')
]

mat = compose_matrix44([0, 0, 0, 0, 90, 90])
brain = []
for name in files:
    brain.append(transform_streamlines(read_ply(name), mat))
draw_bundles(brain, rotate=True)
"""
data1 = read_ply('../data/132118/m_ex_atr-left_shore.ply')
data2 = read_ply('../data/132118/m_ex_atr-right_shore.ply')
draw_bundles([data1,data2])
"""
Example #10
0
import matplotlib.pyplot as plt

from src.tractography.io import read_ply
from src.tractography.Utils import pca_transform_norm
from src.tractography.viz import draw_bundles

data_path = 'data/132118/'
pathways = [
    data_path + fiber for fiber in listdir(data_path)
    if isfile(data_path + fiber)
]

i = 16
print(pathways[i])
print(pathways[i + 1])
static = read_ply(pathways[i])
moving = read_ply(pathways[i + 1])
draw_bundles([moving, static], [[0, 0, 1], [1, 0, 0]])

#moving = new_moving
''' Get points cloud '''
con_static = np.concatenate(static)
con_moving = np.concatenate(moving)
print(np.count_nonzero(con_moving))
''' Build KDTree '''
kdtree = KDTree(con_static)
distances = kdtree.query(con_moving, k=1)[0]
''' Get the threshold '''
max_range = max(distances)
'''
plt.hist(distances, bins='auto',range=(0,max_range))
Example #11
0
Created on Sat Jan 19 23:53:06 2019

@author: mohammed
"""

import sys
from os import path
sys.path.insert(0, path.abspath(path.curdir))

import numpy as np
from sklearn.manifold import Isomap
#from sklearn.decomposition import KernelPCA
from src.tractography.io import read_ply
from src.tractography.viz import isomap_lines_colors, draw_clusters

static = read_ply('data/197348/m_ex_atr-left_shore.ply')
#moving = read_ply('data/197348/m_ex_atr-right_shore.ply')

con_static = np.concatenate(static)
#con_moving = np.concatenate(moving)
'''
new_com = np.zeros((con_static.shape[0]+con_moving.shape[0],3))
new_com[:con_static.shape[0]] = con_static
new_com[con_static.shape[0]:] = con_moving

del static
del moving
del con_static
del con_moving
'''