diff --git a/model_server/base/roiset.py b/model_server/base/roiset.py index 4607b72b0ffcac918cbb8322884452e70e442fe9..503c5b66987f5345c7d179449cd4df58d66a63f4 100644 --- a/model_server/base/roiset.py +++ b/model_server/base/roiset.py @@ -154,18 +154,17 @@ class RoiSet(object): return self._df.itertuples(name='Roi') @staticmethod - def make_df(acc_raw, acc_obj_ids, expand_box_by, deproject=True) -> pd.DataFrame: + def make_df(acc_raw, acc_obj_ids, expand_box_by) -> pd.DataFrame: """ Build dataframe associate object IDs with summary stats :param acc_raw: accessor to raw image data :param acc_obj_ids: accessor to map of object IDs :param expand_box_by: number of pixels to expand bounding box in all directions (without exceeding image boundary) - :param deproject: assign object's z-position based on argmax of raw data if True + # :param deproject: assign object's z-position based on argmax of raw data if True :return: pd.DataFrame """ # build dataframe of objects, assign z index to each object - if deproject: - assert acc_obj_ids.nz == 1, 'Can only deproject a 2D object identity map' + if acc_obj_ids.nz == 1: # deproject objects' z-coordinates from argmax of raw image argmax = acc_raw.data.argmax(axis=3, keepdims=True)[:, :, 0, 0].astype('uint16') df = ( pd.DataFrame( @@ -180,7 +179,7 @@ class RoiSet(object): ) ) df['zi'] = df['intensity_mean'].round().astype('int') - else: + else: # objects' z-coordinates come from arg of max count in object identities map df = ( pd.DataFrame( regionprops_table( @@ -192,7 +191,10 @@ class RoiSet(object): columns={'bbox-0': 'y0', 'bbox-1': 'x0', 'bbox-2': 'y1', 'bbox-3': 'x1', } ) ) - df['zi'] = ... # from somewhere in obmap floor of avg z for each label... + def _get_zi_from_obj_map_counts(la): + return (acc_obj_ids.data == la).sum(axis=(0, 1, 2)).argmax() + + df['zi'] = df['label'].apply(_get_zi_from_obj_map_counts) # compute expanded bounding boxes