Skip to content

Commit

Permalink
add bounding box property for synapses
Browse files Browse the repository at this point in the history
  • Loading branch information
xiuliren committed Jan 5, 2022
1 parent 2e4b99d commit 3439037
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
16 changes: 16 additions & 0 deletions chunkflow/lib/bounding_boxes.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,22 @@ def adjust(self, size: Union[int, tuple, list, Vec]):
self.maxpt += size
return self

def union(self, bbox2: Union[BoundingBox, Bbox]):
"""Merge another bounding box
Args:
bbox2 (Union[BoundingBox, Bbox]): another bounding box
Returns:
BoundingBox: bounding box after merging
"""
if isinstance(bbox2, BoundingBox):
assert self.voxel_size == bbox2.voxel_size

self.minpt = np.minimum(self.minpt, bbox2.minpt)
self.maxpt = np.maximum(self.maxpt, bbox2.maxpt)
return self

def contains(self, point: Union[tuple, Vec, list]):
assert 3 == len(point)
return np.all(np.asarray(
Expand Down
12 changes: 10 additions & 2 deletions chunkflow/lib/synapses.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import numpy as np
import h5py

from .bounding_boxes import BoundingBox


class Synapses():
def __init__(self, pre: np.ndarray, pre_confidence: np.ndarray = None,
Expand Down Expand Up @@ -176,8 +178,14 @@ def pre_with_physical_coordinate(self):
return self.pre * self.resolution
else:
return self.pre



@property
def bounding_box(self) -> BoundingBox:
bbox = BoundingBox.from_points(self.pre)
bbox_post = BoundingBox.from_points(self.post[:, 1:])
bbox.union(bbox_post)
return bbox

@property
def post_with_physical_coordinate(self):
""" post synapses with physical coordinate. Note that the first column is the index of
Expand Down

0 comments on commit 3439037

Please sign in to comment.