Mercurial > repos > imgteam > overlay_images
comparison 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 |
comparison
equal
deleted
inserted
replaced
3:22ff7c705a83 | 4:37662cbf44b8 |
---|---|
31 | 31 |
32 def get_rgb8_copy(img): | 32 def get_rgb8_copy(img): |
33 img = np.squeeze(img) | 33 img = np.squeeze(img) |
34 assert img.ndim == 2 or (img.ndim == 3 and img.shape[-1] in (3, 4)) | 34 assert img.ndim == 2 or (img.ndim == 3 and img.shape[-1] in (3, 4)) |
35 if str(img.dtype).startswith('float'): | 35 if str(img.dtype).startswith('float'): |
36 img = np.round(img * 255).astype('uint8') | 36 img = np.round(img * 255).astype(np.uint8) |
37 elif img.dtype == 'uint16': | 37 elif img.dtype == np.uint16: |
38 img = img // 256 | 38 img = (img // 256).astype(np.uint8) |
39 elif img.dtype != 'uint8': | 39 elif img.dtype != np.uint8: |
40 raise ValueError(f'unknown dtype: {img.dtype}') | 40 raise ValueError(f'unknown dtype: {img.dtype}') |
41 if img.ndim == 2: | 41 if img.ndim == 2: |
42 return np.dstack([img] * 3).copy() | 42 result = np.dstack([img] * 3).copy() |
43 else: | 43 else: |
44 return img[:, :, :3].copy() | 44 result = img[:, :, :3].copy() |
45 assert result.dtype == np.uint8, result.dtype | |
46 return result | |
45 | 47 |
46 | 48 |
47 def coloc_vis(in_red_fn, in_green_fn, out_fn): | 49 def coloc_vis(in_red_fn, in_green_fn, out_fn): |
48 im1 = read_im_gray(in_red_fn) | 50 im1 = read_im_gray(in_red_fn) |
49 im2 = read_im_gray(in_green_fn) | 51 im2 = read_im_gray(in_green_fn) |