Skip to content

Commit

Permalink
Add data op
Browse files Browse the repository at this point in the history
  • Loading branch information
ericup committed Feb 1, 2023
1 parent f3625b9 commit 4e75584
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion celldetection/data/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
This submodule contains data related code and numpy operations.
"""
from .cpn import CPNTargetGenerator, contours2labels, render_contour, clip_contour_, masks2labels, \
labels2contour_list as labels2contours
labels2contour_list as labels2contours, contours2boxes
from .misc import *
from .instance_eval import LabelMatcherList, LabelMatcher
from .segmentation import *
Expand Down
16 changes: 16 additions & 0 deletions celldetection/data/cpn.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,22 @@ def contours2fourier(contours: dict, order=5, dtype=np.float32):
return fouriers, locations


def contours2boxes(contours):
"""Contours to boxes.
Args:
contours: Array[num_contours, num_points, 2]. (x, y) format.
Returns:
Array[num_contours, 4]. (x0, y0, x1, y1) format.
"""
if len(contours):
boxes = np.concatenate((contours.min(1), contours.max(1)), 1)
else:
boxes = np.empty((0, 4))
return boxes


def render_contour(contour, val=1, dtype='int32'):
xmin, ymin = np.floor(np.min(contour, axis=0)).astype('int')
xmax, ymax = np.ceil(np.max(contour, axis=0)).astype('int')
Expand Down

0 comments on commit 4e75584

Please sign in to comment.