示例#1
0
def write_sopath2skeleton(so_path, dest_path, scaling=None, comment=None):
    """
    Writes very simple skeleton, each node represents the center of mass of a
    SV, and edges are created in list order.

    Parameters
    ----------
    so_path : list of SegmentationObject
    dest_path : str
    scaling : np.ndarray or tuple
    comment : str
    """
    if scaling is None:
        scaling = np.array(global_params.config["Dataset"]["scaling"])
    skel = Skeleton()
    anno = SkeletonAnnotation()
    anno.scaling = scaling
    rep_nodes = []
    for so in so_path:
        vert = so.mesh[1].reshape((-1, 3))
        com = np.mean(vert, axis=0)
        kd_tree = spatial.cKDTree(vert)
        dist, nn_ix = kd_tree.query([com])
        nn = vert[nn_ix[0]] / scaling
        n = SkeletonNode().from_scratch(anno, nn[0], nn[1], nn[2])
        anno.addNode(n)
        rep_nodes.append(n)
    for i in range(1, len(rep_nodes)):
        anno.addEdge(rep_nodes[i - 1], rep_nodes[i])
    if comment is not None:
        anno.setComment(comment)
    skel.add_annotation(anno)
    skel.to_kzip(dest_path)
示例#2
0
文件: basics.py 项目: mdraw/SyConn
def coordpath2anno(coords, scaling=None, add_edges=True):
    """
    Creates skeleton from scaled coordinates, assume coords are in order for
    edge creation.

    Parameters
    ----------
    coords : np.array
        scaled cooridnates
    scaling : tuple
    add_edges : bool

    Returns
    -------
    SkeletonAnnotation
    """
    if scaling is None:
        scaling = global_params.config['scaling']
    anno = SkeletonAnnotation()
    anno.scaling = scaling
    scaling = np.array(scaling, dtype=np.int)
    rep_nodes = []
    coords = np.array(coords, dtype=np.int)
    for c in coords:
        unscaled_c = c / scaling
        n = SkeletonNode().from_scratch(anno, unscaled_c[0], unscaled_c[1],
                                        unscaled_c[2])
        anno.addNode(n)
        rep_nodes.append(n)
    if add_edges:
        for i in range(1, len(rep_nodes)):
            anno.addEdge(rep_nodes[i - 1], rep_nodes[i])
    return anno
示例#3
0
def coordpath2anno(coords, scaling=None):
    """
    Creates skeleton from scaled coordinates, assume coords are in order for
    edge creation.

    Parameters
    ----------
    coords : np.array
    scaling : np.ndarray

    Returns
    -------
    SkeletonAnnotation
    """
    if scaling is None:
        scaling = global_params.config["Dataset"]["scaling"]
    anno = SkeletonAnnotation()
    anno.scaling = scaling
    rep_nodes = []
    for c in coords:
        n = SkeletonNode().from_scratch(anno, c[0] / scaling[0],
                                        c[1] / scaling[1], c[2] / scaling[2])
        anno.addNode(n)
        rep_nodes.append(n)
    for i in range(1, len(rep_nodes)):
        anno.addEdge(rep_nodes[i - 1], rep_nodes[i])
    return anno
示例#4
0
def nxGraph2kzip(g, coords, kzip_path):
    import tqdm
    scaling = global_params.config.entries['Dataset']['scaling']()
    coords = coords / scaling
    skel = Skeleton()
    anno = SkeletonAnnotation()
    anno.scaling = scaling
    node_mapping = {}
    pbar = tqdm.tqdm(total=len(coords) + len(g.edges()))
    for v in g.nodes():
        c = coords[v]
        n = SkeletonNode().from_scratch(anno, c[0], c[1], c[2])
        node_mapping[v] = n
        anno.addNode(n)
        pbar.update(1)
    for e in g.edges():
        anno.addEdge(node_mapping[e[0]], node_mapping[e[1]])
        pbar.update(1)
    skel.add_annotation(anno)
    skel.to_kzip(kzip_path)
    pbar.close()