From b5cc552486af43159234ad3d7913ba2d65a7c378 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Al=C3=A1n=20Mu=C3=B1oz?= <alan.munoz@ed.ac.uk> Date: Mon, 27 Feb 2023 15:41:06 +0000 Subject: [PATCH] fix(vis_tools): add rescale and crop_mask --- src/aliby/utils/vis_tools.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/aliby/utils/vis_tools.py b/src/aliby/utils/vis_tools.py index c6d4b7de..c8937d5d 100644 --- a/src/aliby/utils/vis_tools.py +++ b/src/aliby/utils/vis_tools.py @@ -2,8 +2,8 @@ """ Visualisation tools useful to generate figures cell pictures and figures from scripts. """ - import typing as t +from copy import copy import numpy as np @@ -140,3 +140,15 @@ def long_side_vertical(arr): if np.subtract(*arr.shape): result = arr.T return result + + +def rescale(arr): + arr_min = arr.min() + arr_max = arr.max() + return (arr - arr_min) / (arr_max - arr_min) + + +def crop_mask(img: np.ndarray, mask: np.ndarray): + img = copy(img).astype(float) + img[~mask] = np.nan + return img -- GitLab