Skip to content
Snippets Groups Projects
Commit 5df3f720 authored by Christopher Randolph Rhodes's avatar Christopher Randolph Rhodes
Browse files

Filter objects before generating their binary masks

parent c038f5b1
No related branches found
No related tags found
No related merge requests found
......@@ -212,7 +212,7 @@ def filter_df_overlap_seg(df1: pd.DataFrame, df2: pd.DataFrame = None) -> pd.Dat
return dfbb
def make_df_from_object_ids(acc_raw, acc_obj_ids, expand_box_by, deproject_channel=None) -> pd.DataFrame:
def make_df_from_object_ids(acc_raw, acc_obj_ids, expand_box_by, deproject_channel=None, filters=None) -> pd.DataFrame:
"""
Build dataframe that associate object IDs with summary stats;
:param acc_raw: accessor to raw image data
......@@ -258,17 +258,19 @@ def make_df_from_object_ids(acc_raw, acc_obj_ids, expand_box_by, deproject_chann
df = df_insert_slices(df, acc_raw.shape_dict, expand_box_by)
df_fil = filter_df(df, filters)
def _make_binary_mask(r):
acc = InMemoryDataAccessor(acc_obj_ids.data == r.label)
cropped = acc.get_mono(0, mip=True).crop_hw((r.y0, r.x0, (r.y1 - r.y0), (r.x1 - r.x0))).data_yx
return cropped
df['binary_mask'] = df.apply(
df_fil['binary_mask'] = df_fil.apply(
_make_binary_mask,
axis=1,
result_type='reduce',
)
return df
return df_fil
def df_insert_slices(df: pd.DataFrame, sd: dict, expand_box_by) -> pd.DataFrame:
......@@ -387,13 +389,11 @@ class RoiSet(object):
"""
assert acc_obj_ids.chroma == 1
df = filter_df(
make_df_from_object_ids(
acc_raw, acc_obj_ids,
expand_box_by=params.expand_box_by,
deproject_channel=params.deproject_channel,
),
params.filters,
df = make_df_from_object_ids(
acc_raw, acc_obj_ids,
expand_box_by=params.expand_box_by,
deproject_channel=params.deproject_channel,
filters=params.filters,
)
return cls(acc_raw, df, params)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment