From 19cbeaf7f903413c2c55937db12a16ae8cbe0377 Mon Sep 17 00:00:00 2001 From: Lassi Paavolainen Date: Fri, 5 Mar 2021 20:41:32 +0200 Subject: [PATCH] Invert HE images --- wrapper.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/wrapper.py b/wrapper.py index 3e45677..b4a1d98 100644 --- a/wrapper.py +++ b/wrapper.py @@ -32,7 +32,15 @@ def main(argv): fn = os.path.join(in_path, bfimg.filename) img = imageio.imread(fn) if len(img.shape) > 2 and nuc_channel == 0: - img = skimage.color.rgb2gray(img) + gray_rgb = False + if np.array_equal(img[:,:,0],img[:,:,1]) and np.array_equal(img[:,:,0],img[:,:,2]): + gray_rgb = True + img = skimage.color.rgb2gray(img) * 255 + img = img.astype(np.uint8) + # Invert intensity if not grayscale img ie. expect the image + # to be H&E stained image with dark nuclei + if not gray_rgb: + img = np.invert(img) minshape = min(img.shape[:2]) maxshape = max(img.shape[:2]) if minshape != maxshape or minshape < 224: