-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: anistropy not hardcoded (#285)
Co-authored-by: anna-grim <[email protected]>
- Loading branch information
Showing
7 changed files
with
87 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,9 +4,9 @@ | |
@author: Anna Grim | ||
@email: [email protected] | ||
Implementation of subclass of Networkx.Graph called "FragmentsGraph". | ||
NOTE: SAVE LABEL UPDATES --- THERE IS A BUG IN FEATURE GENERATION | ||
Implementation of subclass of Networkx.Graph called "FragmentsGraph" which is | ||
a graph that is initialized by loading swc files (i.e. fragments) from a | ||
predicted segmentation. | ||
""" | ||
import zipfile | ||
|
@@ -30,17 +30,23 @@ class FragmentsGraph(nx.Graph): | |
""" | ||
|
||
def __init__(self, img_bbox=None, node_spacing=1): | ||
def __init__( | ||
self, anisotropy=[1.0, 1.0, 1.0], img_bbox=None, node_spacing=1 | ||
): | ||
""" | ||
Initializes an instance of NeuroGraph. | ||
Parameters | ||
---------- | ||
anisotropy : ArrayLike, optional | ||
Image to physical coordinates scaling factors to account for the | ||
anisotropy of the microscope. The default is [1.0, 1.0, 1.0]. | ||
img_bbox : dict or None, optional | ||
Dictionary with the keys "min" and "max" which specify a bounding | ||
box in an image. The default is None. | ||
node_spacing : int, optional | ||
Spacing (in microns) between nodes. The default is 1. | ||
Physical spacing (in microns) between nodes in swcs. The default | ||
is 1. | ||
Returns | ||
------- | ||
|
@@ -49,6 +55,7 @@ def __init__(self, img_bbox=None, node_spacing=1): | |
""" | ||
super(FragmentsGraph, self).__init__() | ||
# General class attributes | ||
self.anisotropy = anisotropy | ||
self.leaf_kdtree = None | ||
self.node_cnt = 0 | ||
self.node_spacing = node_spacing | ||
|
@@ -908,8 +915,8 @@ def oriented_edge(self, edge, i, key="xyz"): | |
|
||
def is_contained(self, node_or_xyz, buffer=0): | ||
if self.bbox: | ||
coord = self.to_voxels(node_or_xyz) | ||
return util.is_contained(self.bbox, coord, buffer=buffer) | ||
voxel = self.to_voxels(node_or_xyz, self.anisotropy) | ||
return util.is_contained(self.bbox, voxel, buffer=buffer) | ||
else: | ||
return True | ||
|
||
|
@@ -921,13 +928,17 @@ def branch_contained(self, xyz_list): | |
else: | ||
return True | ||
|
||
def to_voxels(self, node_or_xyz, shift=False): | ||
def to_voxels(self, node_or_xyz, shift=np.array([0, 0, 0])): | ||
# Get xyz coordinate | ||
shift = self.origin if shift else np.zeros((3)) | ||
if type(node_or_xyz) is int: | ||
coord = img_util.to_voxels(self.nodes[node_or_xyz]["xyz"]) | ||
xyz = self.nodes[node_or_xyz]["xyz"] | ||
else: | ||
coord = img_util.to_voxels(node_or_xyz) | ||
return coord - shift | ||
xyz = node_or_xyz | ||
|
||
# Coordinate conversion | ||
voxel = img_util.to_voxels(xyz, self.anisotropy) | ||
return voxel - shift | ||
|
||
def is_leaf(self, i): | ||
""" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.