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

Simplified patch export method

parent 3e7e34c7
No related branches found
No related tags found
No related merge requests found
......@@ -92,11 +92,6 @@ def get_patches_from_zmask_meta(
focus_metric: str = None,
**kwargs
) -> pd.DataFrame:
# patches = []
# for mi in zmask_meta:
# dfe = roiset.get_df().assign(patch=object())
# for i, roi in enumerate(dfe.itertuples()):
def _make_patch(roi):
patch3d = roiset.acc_raw.data[roi.slice]
......@@ -161,41 +156,21 @@ def get_patches_from_zmask_meta(
if pad_to:
patch = pad(patch, pad_to)
# patches.append(patch)
return patch
# dfe.loc[i, 'patch'] = patch
dfe = roiset.get_df()
dfe['patch'] = roiset.get_df().apply(lambda r: _make_patch(r), axis=1)
return dfe
# if not make_3d and pc == 1:
# return MonoPatchStack(patches)
# else:
# return Multichannel3dPatchStack(patches)
def export_patches_from_zstack(
where: Path,
# stack: GenericImageDataAccessor,
# zmask_meta: list,
roiset,
rescale_clip: float = 0.0,
pad_to: int = 256,
make_3d: bool = False,
prefix='patch',
focus_metric: str = None,
**kwargs
):
patches_df = get_patches_from_zmask_meta(
roiset,
# stack,
# zmask_meta,
# rescale_clip=rescale_clip,
pad_to=pad_to,
make_3d=make_3d,
focus_metric=focus_metric,
**kwargs
)
make_3d = kwargs.get('make_3d', False)
patches_df = get_patches_from_zmask_meta(roiset, **kwargs)
pc = roiset.acc_raw.chroma
patches = list(patches_df['patch'])
......@@ -204,13 +179,8 @@ def export_patches_from_zstack(
else:
patches_acc = Multichannel3dPatchStack(patches)
exported = []
for i, roi in enumerate(roiset.get_df().itertuples()): # just used for label info
# for i in range(0, len(zmask_meta)):
# mi = zmask_meta[i]
def _export_patch(roi):
patch = patches_acc.iat_yxcz(i)
# obj = mi['info']
# idx = mi['df_index']
ext = 'tif' if make_3d else 'png'
fname = f'{prefix}-la{roi.label:04d}-zi{roi.zi:04d}.{ext}'
......@@ -223,6 +193,11 @@ def export_patches_from_zstack(
'df_index': roi.Index,
'patch_filename': fname,
})
exported = []
for i, roi in enumerate(patches_df.itertuples()): # just used for label info
_export_patch(roi)
return exported
......
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