comparison overlay_images.py @ 6:2495f8b2aefd draft

planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/overlay_images/ commit c86a1b93cb7732f7331a981d13465653cc1a2790
author imgteam
date Wed, 24 Apr 2024 08:12:55 +0000
parents 37662cbf44b8
children
comparison
equal deleted inserted replaced
5:002f7bad3e82 6:2495f8b2aefd
5 See file LICENSE for detail or copy at https://opensource.org/licenses/MIT 5 See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
6 """ 6 """
7 7
8 import argparse 8 import argparse
9 9
10 import giatools.io
10 import matplotlib.colors 11 import matplotlib.colors
11 import matplotlib.pyplot as plt 12 import matplotlib.pyplot as plt
12 import numpy as np 13 import numpy as np
13 import skimage.color 14 import skimage.color
14 import skimage.io 15 import skimage.io
16 import tifffile 17 import tifffile
17 from contours import ContourPaint 18 from contours import ContourPaint
18 19
19 20
20 def read_im_gray(fn): 21 def read_im_gray(fn):
21 img = skimage.io.imread(fn) 22 img = giatools.io.imread(fn)
22 nDims = len(img.shape) 23 nDims = len(img.shape)
23 assert nDims in [2, 3], 'this tool only supports single 2D images' 24 assert nDims in [2, 3], 'this tool only supports single 2D images'
24 if nDims == 3 and img.shape[-1] in [3, 4]: 25 if nDims == 3 and img.shape[-1] in [3, 4]:
25 img = skimage.color.rgb2gray(img) 26 img = skimage.color.rgb2gray(img)
26 if len(img.shape) == 3: 27 if len(img.shape) == 3:
59 out_im[:, :, 1] = (im2 - vmin) * scal 60 out_im[:, :, 1] = (im2 - vmin) * scal
60 skimage.io.imsave(out_fn, out_im) # output is RGB 61 skimage.io.imsave(out_fn, out_im) # output is RGB
61 62
62 63
63 def blending(im1_fn, im2_fn, out_fn, alpha=0.5): 64 def blending(im1_fn, im2_fn, out_fn, alpha=0.5):
64 im1 = skimage.io.imread(im1_fn) 65 im1 = giatools.io.imread(im1_fn)
65 im2 = skimage.io.imread(im2_fn) 66 im2 = giatools.io.imread(im2_fn)
66 assert im1.shape == im2.shape, 'Two images should have the same dimension' 67 assert im1.shape == im2.shape, 'Two images should have the same dimension'
67 out_im = (1 - alpha) * im1 + alpha * im2 68 out_im = (1 - alpha) * im1 + alpha * im2
68 if len(im1.shape) > 3: 69 if len(im1.shape) > 3:
69 tifffile.imwrite(out_fn, out_im.astype(im1.dtype), imagej=True) 70 tifffile.imwrite(out_fn, out_im.astype(im1.dtype), imagej=True)
70 else: 71 else:
71 skimage.io.imsave(out_fn, out_im.astype(im1.dtype)) # format of output is the same as input 72 skimage.io.imsave(out_fn, out_im.astype(im1.dtype)) # format of output is the same as input
72 73
73 74
74 def seg_contour(im1_fn, im2_fn, out_fn, linewidth, color='#ff0000', show_label=False, label_color='#ffff00'): 75 def seg_contour(im1_fn, im2_fn, out_fn, linewidth, color='#ff0000', show_label=False, label_color='#ffff00'):
75 img = skimage.io.imread(im1_fn) 76 img = giatools.io.imread(im1_fn)
76 labels = skimage.io.imread(im2_fn) 77 labels = giatools.io.imread(im2_fn)
77 78
78 result = get_rgb8_copy(img) 79 result = get_rgb8_copy(img)
79 cp = ContourPaint(labels, linewidth, where='center') 80 cp = ContourPaint(labels, linewidth, where='center')
80 color_rgb = np.multiply(255, matplotlib.colors.to_rgb(color)) 81 color_rgb = np.multiply(255, matplotlib.colors.to_rgb(color))
81 82