From 3bddfa5830cb935fd774c6156e9031f683de6e01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Al=C3=A1n=20Mu=C3=B1oz?= <amuoz@ed.ac.uk> Date: Mon, 7 Mar 2022 12:11:09 +0000 Subject: [PATCH] add background_max5 --- extraction/core/functions/defaults.py | 1 + extraction/core/functions/trap.py | 19 ++++++++++++++++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/extraction/core/functions/defaults.py b/extraction/core/functions/defaults.py index 7847fb5a..b7e67bcc 100644 --- a/extraction/core/functions/defaults.py +++ b/extraction/core/functions/defaults.py @@ -30,6 +30,7 @@ def exparams_from_meta(meta: Union[dict, PosixPath, str], extras=["ph"]): "mean", "median", "imBackground", + "background_max5", "max2p5pc", "max2p5pc_med", "max5px", diff --git a/extraction/core/functions/trap.py b/extraction/core/functions/trap.py index 483f97d8..fde16410 100644 --- a/extraction/core/functions/trap.py +++ b/extraction/core/functions/trap.py @@ -4,13 +4,26 @@ import numpy as np def imBackground(cell_masks, trap_image): - ''' + """ :param cell_masks: (numpy 3d array) cells' segmentation mask :param trap_image: the image for the trap in which the cell is (all channels) - ''' + """ if not len(cell_masks): cell_masks = np.zeros_like(trap_image) background = ~cell_masks.sum(axis=2).astype(bool) - return (np.median(trap_image[np.where(background)])) + return np.median(trap_image[np.where(background)]) + + +def background_max5(cell_masks, trap_image): + """ + :param cell_masks: (numpy 3d array) cells' segmentation mask + :param trap_image: the image for the trap in which the cell is (all + channels) + """ + if not len(cell_masks): + cell_masks = np.zeros_like(trap_image) + + background = ~cell_masks.sum(axis=2).astype(bool) + return np.mean(np.sort(trap_image[np.where(background)])[-5:]) -- GitLab