diff overlay_images.py @ 4:37662cbf44b8 draft

planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/overlay_images/ commit 85185439087caafebf1c75dc78b61a2a1f181225
author imgteam
date Fri, 17 Nov 2023 23:34:57 +0000
parents b74693340624
children 2495f8b2aefd
line wrap: on
line diff
--- a/overlay_images.py	Wed Nov 08 19:57:15 2023 +0000
+++ b/overlay_images.py	Fri Nov 17 23:34:57 2023 +0000
@@ -33,15 +33,17 @@
     img = np.squeeze(img)
     assert img.ndim == 2 or (img.ndim == 3 and img.shape[-1] in (3, 4))
     if str(img.dtype).startswith('float'):
-        img = np.round(img * 255).astype('uint8')
-    elif img.dtype == 'uint16':
-        img = img // 256
-    elif img.dtype != 'uint8':
+        img = np.round(img * 255).astype(np.uint8)
+    elif img.dtype == np.uint16:
+        img = (img // 256).astype(np.uint8)
+    elif img.dtype != np.uint8:
         raise ValueError(f'unknown dtype: {img.dtype}')
     if img.ndim == 2:
-        return np.dstack([img] * 3).copy()
+        result = np.dstack([img] * 3).copy()
     else:
-        return img[:, :, :3].copy()
+        result = img[:, :, :3].copy()
+    assert result.dtype == np.uint8, result.dtype
+    return result
 
 
 def coloc_vis(in_red_fn, in_green_fn, out_fn):