Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: compute distance and smoothing #43

Merged
merged 1 commit into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/deep_neurographs/feature_extraction.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions src/deep_neurographs/geometry_utils.py
Original file line number Diff line number Diff line change
@@ -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


Expand Down Expand Up @@ -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):
Expand Down
7 changes: 6 additions & 1 deletion src/deep_neurographs/graph_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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

Expand Down
11 changes: 5 additions & 6 deletions src/deep_neurographs/neurograph.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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"):
Expand Down Expand Up @@ -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)])
Expand Down
Loading