# HG changeset patch
# User imgteam
# Date 1764319262 0
# Node ID 66fe62b9628198bd3aa99af07ee490c2433f035d
# Parent ca362a9bfa20d56ba392e6820d017db2498409ca
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/overlay_images/ commit a11042fbd0da4bfcc54522b31919aa5efb862f3d
diff -r ca362a9bfa20 -r 66fe62b96281 creators.xml
--- a/creators.xml Mon Sep 23 10:26:26 2024 +0000
+++ b/creators.xml Fri Nov 28 08:41:02 2025 +0000
@@ -5,6 +5,11 @@
+
+
+
+
+
@@ -24,5 +29,15 @@
-
+
+
+
+
+
+
+
+
+
+
+
diff -r ca362a9bfa20 -r 66fe62b96281 overlay_images.py
--- a/overlay_images.py Mon Sep 23 10:26:26 2024 +0000
+++ b/overlay_images.py Fri Nov 28 08:41:02 2025 +0000
@@ -30,15 +30,42 @@
return img
-def get_rgb8_copy(img):
+def get_rgb8_copy(img, fp_lower, fp_upper):
img = np.squeeze(img)
assert img.ndim == 2 or (img.ndim == 3 and img.shape[-1] in (3, 4))
+ assert fp_lower == 'min' or abs(float(fp_lower)) < np.inf # 'min' or number
+ assert fp_upper == 'max' or abs(float(fp_upper)) < np.inf # 'max' or number
+
+ # Convert from floating point
if str(img.dtype).startswith('float'):
+ a = img.min() if fp_lower == 'min' else float(fp_lower)
+ b = img.max() if fp_upper == 'max' else float(fp_upper)
+
+ if a > b:
+ raise ValueError(
+ f'Lower bound ({a:g}) must be less than upper bound ({b:g}).'
+ )
+ if a == b:
+ raise ValueError(
+ 'Floating point conversion is undefined'
+ ' because lower and upper bounds are identical.'
+ )
+
+ # Perform linear mapping to [0, 1]
+ img = img.clip(a, b)
+ img = (img - a) / (b - a)
+
+ # Convert to uint8
img = np.round(img * 255).astype(np.uint8)
+
+ # Convert from uint16
elif img.dtype == np.uint16:
img = (img // 256).astype(np.uint8)
+
+ # Other dtypes than float, uint8, uint16 are not supported
elif img.dtype != np.uint8:
raise ValueError(f'unknown dtype: {img.dtype}')
+
if img.ndim == 2:
result = np.dstack([img] * 3).copy()
else:
@@ -72,11 +99,11 @@
skimage.io.imsave(out_fn, out_im.astype(im1.dtype)) # format of output is the same as input
-def seg_contour(im1_fn, im2_fn, out_fn, linewidth, color='#ff0000', show_label=False, label_color='#ffff00'):
+def seg_contour(im1_fn, im2_fn, out_fn, fp_lower, fp_upper, linewidth, color='#ff0000', show_label=False, label_color='#ffff00'):
img = giatools.io.imread(im1_fn)
labels = giatools.io.imread(im2_fn)
- result = get_rgb8_copy(img)
+ result = get_rgb8_copy(img, fp_lower, fp_upper)
cp = ContourPaint(labels, linewidth, where='center')
color_rgb = np.multiply(255, matplotlib.colors.to_rgb(color))
@@ -106,6 +133,8 @@
parser.add_argument("im2", help="The second image")
parser.add_argument("out", help="Output image")
parser.add_argument('--method', dest='method', default='coloc_vis', help='How to overlay images')
+ parser.add_argument('--fp_lower', default='0', type=str, help='Lower bound for floating point conversion')
+ parser.add_argument('--fp_upper', default='1', type=str, help='Upper bound for floating point conversion')
parser.add_argument('--alpha', dest='alpha', default=0.5, type=float, help='Blending weight')
parser.add_argument('--thickness', dest='thickness', default=2, type=int, help='Contour thickness')
parser.add_argument('--color', dest='color', default='#FF0000', help='Contour color')
@@ -118,8 +147,14 @@
elif args.method == 'blending':
blending(args.im1, args.im2, args.out, alpha=args.alpha)
elif args.method == 'seg_contour':
- seg_contour(args.im1, args.im2, args.out,
- linewidth=args.thickness,
- color=args.color,
- show_label=args.show_label,
- label_color=args.label_color)
+ seg_contour(
+ args.im1,
+ args.im2,
+ args.out,
+ fp_lower=args.fp_lower,
+ fp_upper=args.fp_upper,
+ linewidth=args.thickness,
+ color=args.color,
+ show_label=args.show_label,
+ label_color=args.label_color,
+ )
diff -r ca362a9bfa20 -r 66fe62b96281 overlay_images.xml
--- a/overlay_images.xml Mon Sep 23 10:26:26 2024 +0000
+++ b/overlay_images.xml Fri Nov 28 08:41:02 2025 +0000
@@ -1,13 +1,13 @@
-
+
creators.xml
tests.xml
- 0.0.4
- 4
+ 0.0.5
+
@@ -17,7 +17,7 @@
galaxy_image_analysis
- scikit-image
+ scikit-image
matplotlib
tifffile
numpy
@@ -31,12 +31,14 @@
#if $method_option.method == "seg_contour"
./output.png
#else
- ./output.tif
+ ./output.tiff
#end if
--method $method_option.method
#if $method_option.method == "blending"
--alpha $method_option.alpha
#elif $method_option.method == "seg_contour"
+ --fp_lower '${method_option.fp_conversion.lower}'
+ --fp_upper '${method_option.fp_conversion.upper}'
--thickness $method_option.thickness
--color '$method_option.color'
$method_option.show_label
@@ -46,32 +48,50 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
method_option['method'] != 'seg_contour'
@@ -80,51 +100,159 @@
-
-
-
-
+
+
+
+
+
+
-
-
-
-
-
+
+
+
+
+
+
+
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
-
-
-
-
-
+
+
+
+
+
+
+
+
-
-
-
-
-
+
+
+
+
+
+
+
+
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+