Skip to content
Snippets Groups Projects

RoiSet facilitates object detection models

Merged Christopher Randolph Rhodes requested to merge dev_obj_det into staging
2 files
+ 49
23
Compare changes
  • Side-by-side
  • Inline
Files
2
+ 35
15
@@ -10,6 +10,7 @@ from pydantic import BaseModel
from scipy.stats import moment
from skimage.filters import sobel
from skimage import draw
from skimage.measure import approximate_polygon, find_contours, label, points_in_poly, regionprops, regionprops_table, shannon_entropy
from skimage.morphology import binary_dilation, disk
@@ -181,10 +182,6 @@ def make_df_from_object_ids(acc_raw, acc_obj_ids, expand_box_by) -> pd.DataFrame
)
return df
# TODO: implement
def make_df_from_polygons(acc_raw, polygons:np.ndarray) -> pd.DataFrame:
pass
def df_insert_slices(df: pd.DataFrame, sd: dict, expand_box_by) -> pd.DataFrame:
h = sd['Y']
@@ -345,20 +342,43 @@ class RoiSet(object):
Create a RoiSet from a binary segmentation mask (either 2D or 3D)
:param acc_raw: accessor to a generally a multichannel z-stack
:param acc_seg: accessor of a binary segmentation mask (mono) of either two or three dimensions
:param allow_3d: return a 3D map if True; return a 2D map of the mask's maximum intensity project if False
:param allow_3d: use a 3D map if True; use a 2D map of the mask's maximum intensity project if False
:param connect_3d: objects can span multiple z-positions if True; objects are unique to a single z if False
:param params: optional arguments that influence the definition and representation of ROIs
:return: object identities map
"""
return RoiSet.from_object_ids(acc_raw, get_label_ids(acc_seg, allow_3d=allow_3d, connect_3d=connect_3d), params)
return RoiSet.from_object_ids(
acc_raw,
get_label_ids(
acc_seg,
allow_3d=allow_3d,
connect_3d=connect_3d
),
params
)
@staticmethod
#TODO: implement
def from_polygons(acc_raw, polygons: np.ndarray):
binary_poly = np.zeros(acc_raw.mono(0).shape, dtype=bool)
for p in poly:
pidcs = draw.polygon(p[:, 1], p[:, 0])
binary_poly[pidcs] = True
def from_polygons_2d(
acc_raw,
polygons: List[np.ndarray],
params: RoiSetMetaParams = RoiSetMetaParams()
):
"""
Create a RoiSet where objects are defined from a list of polygon coordinates
:param acc_raw: accessor to a generally a multichannel z-stack
:param polygons: list of (variable x 2) np.ndarrays describing (x, y) polymer coordinates
:param params: optional arguments that influence the definition and representation of ROIs
"""
mask = np.zeros(acc_raw.get_mono(0, mip=True).shape, dtype=bool)
for p in polygons:
sl = draw.polygon(p[:, 1], p[:, 0])
mask[sl] = True
return RoiSet.from_binary_mask(
acc_raw,
InMemoryDataAccessor(mask),
allow_3d=False,
connect_3d=False,
params=params,
)
# TODO: get overlapping segments
@@ -394,7 +414,7 @@ class RoiSet(object):
write_accessor_data_to_file(fp, annotated)
return (prefix + '.tif')
def get_zmask(self, mask_type='boxes'):
def get_zmask(self, mask_type='boxes') -> np.ndarray:
"""
Return a mask of same dimensionality as raw data
@@ -780,7 +800,7 @@ class RoiSet(object):
return record
def get_polygons(self, poly_threshold=0, dilation_radius=1) -> pd.DataFrame:
"""
self.coordinates_ = """
Fit polygons to all object boundaries in the RoiSet
:param poly_threshold: threshold distance for polygon fit; a smaller number follows sharp features more closely
:param dilation_radius: radius of binary dilation to apply before fitting polygon
Loading