| Previous changeset 8:ca362a9bfa20 (2024-09-23) |
|
Commit message:
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/overlay_images/ commit a11042fbd0da4bfcc54522b31919aa5efb862f3d |
|
modified:
creators.xml overlay_images.py overlay_images.xml |
|
added:
test-data/mask1.tiff test-data/mask1r.tiff test-data/mask2.tiff test-data/mask3.tiff test-data/sample1_uint16.tiff test-data/sample1_uint8.tiff test-data/sample2.tiff test-data/sample3.tiff test-data/test1.tiff test-data/test10.png test-data/test2.tiff test-data/test6.png test-data/test7.png test-data/test8.png test-data/test9.png |
|
removed:
test-data/mask1.tif test-data/mask1r.tif test-data/mask2.tif test-data/sample1_uint16.tif test-data/sample1_uint8.tif test-data/test1.tif test-data/test2.tif |
| b |
| 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 |
| b |
| @@ -5,6 +5,11 @@ <yield /> </xml> + <xml name="creators/kostrykin"> + <person givenName="Leonid" familyName="Kostrykin"/> + <yield/> + </xml> + <xml name="creators/rmassei"> <person givenName="Riccardo" familyName="Massei"/> <yield/> @@ -24,5 +29,15 @@ <person givenName="Till" familyName="Korten"/> <yield/> </xml> - + + <xml name="creators/pavanvidem"> + <person givenName="Pavan" familyName="Videm"/> + <yield/> + </xml> + + <xml name="creators/tuncK"> + <person givenName="Tunc" familyName="Kayikcioglu"/> + <yield/> + </xml> + </macros> |
| b |
| 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, + ) |
| b |
| 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 |
| [ |
| b'@@ -1,13 +1,13 @@\n-<tool id="ip_overlay_images" name="Overlay images" version="@TOOL_VERSION@+galaxy@VERSION_SUFFIX@" profile="20.05">\r\n+<tool id="ip_overlay_images" name="Overlay images" version="@TOOL_VERSION@" profile="20.05">\r\n <description></description>\r\n <macros>\r\n <import>creators.xml</import>\r\n <import>tests.xml</import>\r\n- <token name="@TOOL_VERSION@">0.0.4</token>\r\n- <token name="@VERSION_SUFFIX@">4</token>\r\n+ <token name="@TOOL_VERSION@">0.0.5</token>\r\n </macros>\r\n <creator>\r\n <expand macro="creators/bmcv"/>\r\n+ <expand macro="creators/kostrykin"/>\r\n <expand macro="creators/thawn"/>\r\n </creator>\r\n <edam_operations>\r\n@@ -17,7 +17,7 @@\n <xref type="bio.tools">galaxy_image_analysis</xref>\r\n </xrefs>\r\n <requirements>\r\n- <requirement type="package" version="0.18.1">scikit-image</requirement> \r\n+ <requirement type="package" version="0.18.1">scikit-image</requirement>\r\n <requirement type="package" version="3.3.4">matplotlib</requirement>\r\n <requirement type="package" version="2020.10.1">tifffile</requirement>\r\n <requirement type="package" version="1.21">numpy</requirement>\r\n@@ -31,12 +31,14 @@\n #if $method_option.method == "seg_contour"\r\n ./output.png\r\n #else\r\n- ./output.tif\r\n+ ./output.tiff\r\n #end if\r\n --method $method_option.method\r\n #if $method_option.method == "blending"\r\n --alpha $method_option.alpha\r\n #elif $method_option.method == "seg_contour"\r\n+ --fp_lower \'${method_option.fp_conversion.lower}\'\r\n+ --fp_upper \'${method_option.fp_conversion.upper}\'\r\n --thickness $method_option.thickness\r\n --color \'$method_option.color\'\r\n $method_option.show_label\r\n@@ -46,32 +48,50 @@\n </command>\r\n <inputs>\r\n <conditional name="method_option">\r\n+\r\n <param name="method" type="select" label="Type of the overlay">\r\n <option value="coloc_vis" selected="True">Colocalization</option>\r\n <option value="blending">Linear blending</option>\r\n <option value="seg_contour">Segmentation contours over image</option>\r\n </param>\r\n+\r\n <when value="coloc_vis">\r\n <param name="im1" type="data" format="tiff,png" label="Image 1 (red channel)" />\r\n <param name="im2" type="data" format="tiff,png" label="Image 2 (green channel)" />\r\n </when>\r\n+\r\n <when value="blending">\r\n <param name="im1" type="data" format="tiff,png" label="Image 1" />\r\n <param name="im2" type="data" format="tiff,png" label="Image 2" />\r\n <param name="alpha" type="float" value="0.5" min="0.0" max="1.0" label="The weight for blending: result = (1 - weight) * image1 + weight * image2." />\r\n </when>\r\n+\r\n <when value="seg_contour">\r\n <param name="im1" type="data" format="tiff,png" label="Intensity image" />\r\n+\r\n+ <section name="fp_conversion" title="Intensity image floating point conversion" expanded="false" help="This is only used if the values of the intensity image have a floating point format. Overlay images are created as PNG files, that do not support floating point values (but only integer values between 0 and 255). Conversion of floating point intensity values to integer values via linear mapping is generally ambiguous and can be adapted here.">\r\n+ <param name="lower" type="select" label="Lower bound conversion" help="Choose which floating point intensity value will be mapped to 0 (i.e. black if grayscale).">\r\n+ <option value="0" selected="True">0</option>\r\n+ <option value="-1">-1</option>\r\n+ <option value="min">Minimum value of the image</option>\r\n+ '..b'"/>\r\n+ <param name="thickness" value="1"/>\r\n+ <param name="color" value="#ff0000"/>\r\n+ <param name="label_color" value="#ffff00"/>\r\n+ <section name="fp_conversion">\r\n+ <param name="lower" value="-1"/>\r\n+ <param name="upper" value="1"/>\r\n+ </section>\r\n+ </conditional>\r\n+ <expand macro="tests/intensity_image_diff" name="out_png" value="test7.png" ftype="png"/>\r\n+ </test>\r\n+ <test expect_num_outputs="1"><!-- segmentation overlay, floating point conversion test min/1 -->\r\n+ <conditional name="method_option">\r\n+ <param name="method" value="seg_contour"/>\r\n+ <param name="im1" value="sample2.tiff"/>\r\n+ <param name="im2" value="mask3.tiff"/>\r\n+ <param name="thickness" value="1"/>\r\n+ <param name="color" value="#ff0000"/>\r\n+ <param name="label_color" value="#ffff00"/>\r\n+ <section name="fp_conversion">\r\n+ <param name="lower" value="min"/>\r\n+ <param name="upper" value="1"/>\r\n+ </section>\r\n+ </conditional>\r\n+ <expand macro="tests/intensity_image_diff" name="out_png" value="test8.png" ftype="png"/>\r\n+ </test>\r\n+ <test expect_num_outputs="1"><!-- segmentation overlay, floating point conversion test 0/max -->\r\n+ <conditional name="method_option">\r\n+ <param name="method" value="seg_contour"/>\r\n+ <param name="im1" value="sample2.tiff"/>\r\n+ <param name="im2" value="mask3.tiff"/>\r\n+ <param name="thickness" value="1"/>\r\n+ <param name="color" value="#ff0000"/>\r\n+ <param name="label_color" value="#ffff00"/>\r\n+ <section name="fp_conversion">\r\n+ <param name="lower" value="0"/>\r\n+ <param name="upper" value="max"/>\r\n+ </section>\r\n+ </conditional>\r\n+ <expand macro="tests/intensity_image_diff" name="out_png" value="test9.png" ftype="png"/>\r\n+ </test>\r\n+ <test expect_num_outputs="1"><!-- segmentation overlay, floating point conversion test min/max -->\r\n+ <conditional name="method_option">\r\n+ <param name="method" value="seg_contour"/>\r\n+ <param name="im1" value="sample2.tiff"/>\r\n+ <param name="im2" value="mask3.tiff"/>\r\n+ <param name="thickness" value="1"/>\r\n+ <param name="color" value="#ff0000"/>\r\n+ <param name="label_color" value="#ffff00"/>\r\n+ <section name="fp_conversion">\r\n+ <param name="lower" value="min"/>\r\n+ <param name="upper" value="max"/>\r\n+ </section>\r\n+ </conditional>\r\n+ <expand macro="tests/intensity_image_diff" name="out_png" value="test10.png" ftype="png"/>\r\n+ </test>\r\n+ <test expect_failure="true"><!-- segmentation overlay, floating point conversion test with illegal settings -->\r\n+ <conditional name="method_option">\r\n+ <param name="method" value="seg_contour"/>\r\n+ <param name="im1" value="sample3.tiff"/>\r\n+ <param name="im2" value="mask3.tiff"/>\r\n+ <param name="thickness" value="1"/>\r\n+ <param name="color" value="#ff0000"/>\r\n+ <param name="label_color" value="#ffff00"/>\r\n+ <section name="fp_conversion">\r\n+ <param name="lower" value="0"/>\r\n+ <param name="upper" value="max"/>\r\n+ </section>\r\n+ </conditional>\r\n+ <assert_stderr>\r\n+ <has_text text="Lower bound (0) must be less than upper bound (-10)." />\r\n+ </assert_stderr>\r\n+ </test>\r\n </tests>\r\n <help><![CDATA[\r\n \r\n' |
| b |
| diff -r ca362a9bfa20 -r 66fe62b96281 test-data/mask1.tif |
| b |
| Binary file test-data/mask1.tif has changed |
| b |
| diff -r ca362a9bfa20 -r 66fe62b96281 test-data/mask1.tiff |
| b |
| Binary file test-data/mask1.tiff has changed |
| b |
| diff -r ca362a9bfa20 -r 66fe62b96281 test-data/mask1r.tif |
| b |
| Binary file test-data/mask1r.tif has changed |
| b |
| diff -r ca362a9bfa20 -r 66fe62b96281 test-data/mask1r.tiff |
| b |
| Binary file test-data/mask1r.tiff has changed |
| b |
| diff -r ca362a9bfa20 -r 66fe62b96281 test-data/mask2.tif |
| b |
| Binary file test-data/mask2.tif has changed |
| b |
| diff -r ca362a9bfa20 -r 66fe62b96281 test-data/mask2.tiff |
| b |
| Binary file test-data/mask2.tiff has changed |
| b |
| diff -r ca362a9bfa20 -r 66fe62b96281 test-data/mask3.tiff |
| b |
| Binary file test-data/mask3.tiff has changed |
| b |
| diff -r ca362a9bfa20 -r 66fe62b96281 test-data/sample1_uint16.tif |
| b |
| Binary file test-data/sample1_uint16.tif has changed |
| b |
| diff -r ca362a9bfa20 -r 66fe62b96281 test-data/sample1_uint16.tiff |
| b |
| Binary file test-data/sample1_uint16.tiff has changed |
| b |
| diff -r ca362a9bfa20 -r 66fe62b96281 test-data/sample1_uint8.tif |
| b |
| Binary file test-data/sample1_uint8.tif has changed |
| b |
| diff -r ca362a9bfa20 -r 66fe62b96281 test-data/sample1_uint8.tiff |
| b |
| Binary file test-data/sample1_uint8.tiff has changed |
| b |
| diff -r ca362a9bfa20 -r 66fe62b96281 test-data/sample2.tiff |
| b |
| Binary file test-data/sample2.tiff has changed |
| b |
| diff -r ca362a9bfa20 -r 66fe62b96281 test-data/sample3.tiff |
| b |
| Binary file test-data/sample3.tiff has changed |
| b |
| diff -r ca362a9bfa20 -r 66fe62b96281 test-data/test1.tif |
| b |
| Binary file test-data/test1.tif has changed |
| b |
| diff -r ca362a9bfa20 -r 66fe62b96281 test-data/test1.tiff |
| b |
| Binary file test-data/test1.tiff has changed |
| b |
| diff -r ca362a9bfa20 -r 66fe62b96281 test-data/test10.png |
| b |
| Binary file test-data/test10.png has changed |
| b |
| diff -r ca362a9bfa20 -r 66fe62b96281 test-data/test2.tif |
| b |
| Binary file test-data/test2.tif has changed |
| b |
| diff -r ca362a9bfa20 -r 66fe62b96281 test-data/test2.tiff |
| b |
| Binary file test-data/test2.tiff has changed |
| b |
| diff -r ca362a9bfa20 -r 66fe62b96281 test-data/test6.png |
| b |
| Binary file test-data/test6.png has changed |
| b |
| diff -r ca362a9bfa20 -r 66fe62b96281 test-data/test7.png |
| b |
| Binary file test-data/test7.png has changed |
| b |
| diff -r ca362a9bfa20 -r 66fe62b96281 test-data/test8.png |
| b |
| Binary file test-data/test8.png has changed |
| b |
| diff -r ca362a9bfa20 -r 66fe62b96281 test-data/test9.png |
| b |
| Binary file test-data/test9.png has changed |