diff --git a/src/deep_neurographs/feature_extraction.py b/src/deep_neurographs/feature_extraction.py index 99afa2a..4af758c 100644 --- a/src/deep_neurographs/feature_extraction.py +++ b/src/deep_neurographs/feature_extraction.py @@ -243,7 +243,7 @@ def generate_img_profiles( ) img = utils.normalize_img(img) for edge in neurograph.mutable_edges: - xyz_i, xyz_j = neurograph.get_edge_attr("xyz", edge) + xyz_i, xyz_j = neurograph.get_edge_attr(edge, "xyz") xyz_i = utils.world_to_img(neurograph, xyz_i) xyz_j = utils.world_to_img(neurograph, xyz_j) path = geometry_utils.make_line(xyz_i, xyz_j, N_PROFILE_POINTS) diff --git a/src/deep_neurographs/geometry_utils.py b/src/deep_neurographs/geometry_utils.py index 634cec6..4b0d459 100644 --- a/src/deep_neurographs/geometry_utils.py +++ b/src/deep_neurographs/geometry_utils.py @@ -1,10 +1,11 @@ import heapq +import math from copy import deepcopy import numpy as np from scipy.interpolate import UnivariateSpline from scipy.linalg import svd - +from scipy.spatial import distance from deep_neurographs import utils @@ -427,7 +428,7 @@ def dist(v_1, v_2, metric="l2"): if metric == "l1": return np.linalg.norm(np.subtract(v_1, v_2), ord=1) else: - return np.linalg.norm(np.subtract(v_1, v_2), ord=2) + return distance.euclidean(v_1, v_2) def make_line(xyz_1, xyz_2, num_steps): diff --git a/src/deep_neurographs/graph_utils.py b/src/deep_neurographs/graph_utils.py index 9f7b221..16798d3 100644 --- a/src/deep_neurographs/graph_utils.py +++ b/src/deep_neurographs/graph_utils.py @@ -92,6 +92,11 @@ def get_irreducibles(swc_dict, swc_id=None, prune=True, depth=16, smooth=True): nbs = utils.append_dict_value(nbs, root, j) nbs = utils.append_dict_value(nbs, j, root) root = None + + if all(attrs["xyz"][0] == attrs["xyz"][-1]): + print(root, j) + print(attrs) + stop # Output leafs = set_node_attrs(swc_dict, leafs) @@ -290,7 +295,7 @@ def upd_endpoint_xyz(edges, key, old_xyz, new_xyz): """ if all(edges[key]["xyz"][0] == old_xyz): edges[key]["xyz"][0] = new_xyz - else: + elif all(edges[key]["xyz"][-1] == old_xyz): edges[key]["xyz"][-1] = new_xyz return edges diff --git a/src/deep_neurographs/neurograph.py b/src/deep_neurographs/neurograph.py index a68b70b..ffe7c71 100644 --- a/src/deep_neurographs/neurograph.py +++ b/src/deep_neurographs/neurograph.py @@ -352,7 +352,7 @@ def init_targets(self, target_neurograph): edge = proposals[idx] if self.is_simple(edge): add_bool = self.is_target( - target_neurograph, edge, dist=5, ratio=0.7, exclude=10 + target_neurograph, edge, dist=3, ratio=0.7, exclude=5 ) if add_bool: self.target_edges.add(edge) @@ -364,7 +364,7 @@ def init_targets(self, target_neurograph): for idx in np.argsort(dists): edge = remaining_proposals[idx] add_bool = self.is_target( - target_neurograph, edge, dist=7, ratio=0.4, exclude=15 + target_neurograph, edge, dist=5, ratio=0.5, exclude=5 ) if add_bool: self.target_edges.add(edge) @@ -517,7 +517,7 @@ def get_immutable_nbs(self, i): return nbs def compute_length(self, edge, metric="l2"): - xyz_1, xyz_2 = self.get_edge_attr("xyz", edge) + xyz_1, xyz_2 = self.get_edge_attr(edge, "xyz") return get_dist(xyz_1, xyz_2, metric=metric) def path_length(self, metric="l2"): @@ -555,10 +555,9 @@ def creates_cycle(self, edge): self.predicted_graph.remove_edges_from([edge]) return True - def get_edge_attr(self, key, edge): - i, j = edge + def get_edge_attr(self, edge, key): xyz_arr = gutils.get_edge_attr(self, edge, key) - return xyz_arr[0], xyz_arr[1] + return xyz_arr[0], xyz_arr[-1] def get_complex_proposals(self): return set([e for e in self.mutable_edges if not self.is_simple(e)])