Mercurial > repos > imgteam > concat_channels
changeset 3:4c43875c790c draft
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/concat_channels/ commit c045f067a57e8308308cf6329060c7ccd3fc372f
author | imgteam |
---|---|
date | Thu, 04 Apr 2024 15:25:29 +0000 |
parents | 212627bfb759 |
children | 2592a29a785e |
files | concat_channels.py concat_channels.xml creators.xml test-data/input1_uint8.png test-data/input2_float.tiff test-data/out.tiff test-data/res.tiff test-data/res_preserve_brightness.tiff test-data/res_preserve_values.tiff test-data/sample1.png test-data/sample2.png tests.xml |
diffstat | 12 files changed, 193 insertions(+), 28 deletions(-) [+] |
line wrap: on
line diff
--- a/concat_channels.py Mon Nov 13 22:10:47 2023 +0000 +++ b/concat_channels.py Thu Apr 04 15:25:29 2024 +0000 @@ -1,33 +1,42 @@ import argparse -import warnings import numpy as np import skimage.io import skimage.util -def concat_channels(input_image_paths, output_image_path, axis): +def concat_channels(input_image_paths, output_image_path, axis, preserve_values): images = [] for image_path in input_image_paths: + raw_image = skimage.io.imread(image_path) if len(raw_image.shape) == 2: if axis == 0: raw_image = [raw_image] else: raw_image = np.expand_dims(raw_image, 2) + + # Preserve values: Convert to `float` dtype without changing the values + if preserve_values: + raw_image = raw_image.astype(float) + + # Preserve brightness: Scale values to 0..1 + else: + raw_image = skimage.util.img_as_float(raw_image) + images.append(raw_image) + + # Do the concatenation and save res = np.concatenate(images, axis) - with warnings.catch_warnings(): - warnings.simplefilter("ignore") - res = skimage.util.img_as_uint(res) # Attention: precision loss - skimage.io.imsave(output_image_path, res, plugin='tifffile') + skimage.io.imsave(output_image_path, res, plugin='tifffile') if __name__ == "__main__": parser = argparse.ArgumentParser() - parser.add_argument('input_files', type=argparse.FileType('r'), nargs='+', help='input file') - parser.add_argument('-o', dest='out_file', type=argparse.FileType('w'), help='out file (TIFF)') - parser.add_argument('--axis', dest='axis', type=int, default=0, choices=[0, 2], help='concatenation axis') + parser.add_argument('input_files', type=argparse.FileType('r'), nargs='+') + parser.add_argument('-o', dest='out_file', type=argparse.FileType('w')) + parser.add_argument('--axis', dest='axis', type=int, default=0, choices=[0, 2]) + parser.add_argument('--preserve_values', default=False, action='store_true') args = parser.parse_args() - concat_channels([x.name for x in args.input_files], args.out_file.name, args.axis) + concat_channels([x.name for x in args.input_files], args.out_file.name, args.axis, args.preserve_values)
--- a/concat_channels.xml Mon Nov 13 22:10:47 2023 +0000 +++ b/concat_channels.xml Thu Apr 04 15:25:29 2024 +0000 @@ -1,5 +1,12 @@ -<tool id="ip_concat_channels" name="Concatenate images or channels" version="0.2-2"> +<tool id="ip_concat_channels" name="Concatenate images or channels" version="0.3-0" profile="20.05"> <description></description> + <macros> + <import>creators.xml</import> + <import>tests.xml</import> + </macros> + <creator> + <expand macro="creators/bmcv"/> + </creator> <edam_operations> <edam_operation>operation_3443</edam_operation> </edam_operations> @@ -7,40 +14,71 @@ <xref type="bio.tools">galaxy_image_analysis</xref> </xrefs> <requirements> - <requirement type="package" version="0.14.2">scikit-image</requirement> - <requirement type="package" version="1.15.4">numpy</requirement> - <requirement type="package" version="0.15.1">tifffile</requirement> + <requirement type="package" version="0.18.3">scikit-image</requirement> + <requirement type="package" version="1.24.1">numpy</requirement> + <requirement type="package" version="2021.7.2">tifffile</requirement> </requirements> - <command detect_errors="aggressive"> - <![CDATA[ - python '$__tool_directory__/concat_channels.py' + <command detect_errors="aggressive"><![CDATA[ + + python '$__tool_directory__/concat_channels.py' + #for $input in $inputs - '$input' + '$input' #end for + + $mode + -o '$output' --axis '$axis' - ]]> - </command> + + ]]></command> <inputs> - <param name="inputs" type="data" multiple="true" format="tiff,png,jpg,bmp" label="Binary Image Files" help="one or multiple binary image fiels"/> - <param name="axis" type="select" label="Concatenation Axis"> - <option value="0">0</option> - <option value="2">2</option> + <param name="inputs" type="data" multiple="true" format="tiff,png" label="Images to concatenate"/> + <param name="axis" type="integer" min="0" value="0" label="Concatenation axis" help="The images will be concatenated along this axis. For a 2-D image, a value of 0 corresponds to horizontal concatenation, and a value of 1 to vertical concatenation. For an RGB image, a value of 2 corresponds to concatenation of the channels of the images."/> + <param name="mode" type="select" label="Scaling of values" help="If the brightness is to be preserved (default), then the values will be scaled between 0 and 1, and the pixel type will be float."> + <option value="" selected="true">Preserve brightness</option> + <option value="--preserve_values">Preserve range of values</option> </param> </inputs> <outputs> <data format="tiff" name="output"/> </outputs> <tests> + <!-- Test with "preserve brightness" --> <test> - <param name="inputs" value="sample1.png,sample2.png"/> + <param name="inputs" value="input1_uint8.png,input2_float.tiff"/> + <param name="axis" value="0"/> + <param name="mode" value=""/> + <expand macro="tests/intensity_image_diff" name="output" value="res_preserve_brightness.tiff" ftype="tiff"/> + </test> + <!-- Test with "preserve range of values" --> + <test> + <param name="inputs" value="input1_uint8.png,input2_float.tiff"/> <param name="axis" value="0"/> - <output name="output" value="res.tiff" ftype="tiff" compare="sim_size"/> + <param name="mode" value="--preserve_values"/> + <expand macro="tests/intensity_image_diff" name="output" value="res_preserve_values.tiff" ftype="tiff"> + <!-- + + The input files have values ranging between 0 and 255. + + Below, we use an assertion in addition to the `image_diff` comparison, to ensure that the range of + values is preserved. The motiviation behind this is that the expectation images are usually checked + visually, which means that the `image_diff` comparison is likely to ensure that the brightness of + the image is correct, thus it's good to double-check the range of values. + + --> + <has_image_mean_intensity min="0" max="255"/> + </expand> </test> </tests> <help> - **What it does** + + **Concatenates images along arbitrary axes.** - This tool concatenates images. + This can be used, for example, to spatially concatenate images, or along their channels. + + This tool either preserves the image brightness, or the range of values. + In general, both cannot be preserved when concatenating images of different pixel types (e.g., uint8 and uint16). + </help> <citations> <citation type="doi">10.1016/j.jbiotec.2017.07.019</citation>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/creators.xml Thu Apr 04 15:25:29 2024 +0000 @@ -0,0 +1,23 @@ +<macros> + + <xml name="creators/bmcv"> + <organization name="Biomedical Computer Vision Group, Heidelberg Universtiy" alternateName="BMCV" url="http://www.bioquant.uni-heidelberg.de/research/groups/biomedical_computer_vision.html" /> + <yield /> + </xml> + + <xml name="creators/alliecreason"> + <person givenName="Allison" familyName="Creason"/> + <yield/> + </xml> + + <xml name="creators/bugraoezdemir"> + <person givenName="Bugra" familyName="Oezdemir"/> + <yield/> + </xml> + + <xml name="creators/thawn"> + <person givenName="Till" familyName="Korten"/> + <yield/> + </xml> + +</macros>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests.xml Thu Apr 04 15:25:29 2024 +0000 @@ -0,0 +1,95 @@ +<macros> + + <!-- Macros for verification of image outputs --> + + <xml + name="tests/binary_image_diff" + tokens="name,value,ftype,metric,eps" + token_metric="mae" + token_eps="0.01"> + + <output name="@NAME@" value="@VALUE@" ftype="@FTYPE@" compare="image_diff" metric="@METRIC@" eps="@EPS@" pin_labels="0"> + <assert_contents> + <has_image_n_labels n="2"/> + <yield/> + </assert_contents> + </output> + + </xml> + + <xml + name="tests/label_image_diff" + tokens="name,value,ftype,metric,eps,pin_labels" + token_metric="iou" + token_eps="0.01" + token_pin_labels="0"> + + <output name="@NAME@" value="@VALUE@" ftype="@FTYPE@" compare="image_diff" metric="@METRIC@" eps="@EPS@" pin_labels="@PIN_LABELS@"> + <assert_contents> + <yield/> + </assert_contents> + </output> + + </xml> + + <xml + name="tests/intensity_image_diff" + tokens="name,value,ftype,metric,eps" + token_metric="rms" + token_eps="0.01"> + + <output name="@NAME@" value="@VALUE@" ftype="@FTYPE@" compare="image_diff" metric="@METRIC@" eps="@EPS@"> + <assert_contents> + <yield/> + </assert_contents> + </output> + + </xml> + + <!-- Variants of the above for verification of collection elements --> + + <xml + name="tests/binary_image_diff/element" + tokens="name,value,ftype,metric,eps" + token_metric="mae" + token_eps="0.01"> + + <element name="@NAME@" value="@VALUE@" ftype="@FTYPE@" compare="image_diff" metric="@METRIC@" eps="@EPS@" pin_labels="0"> + <assert_contents> + <has_image_n_labels n="2"/> + <yield/> + </assert_contents> + </element> + + </xml> + + <xml + name="tests/label_image_diff/element" + tokens="name,value,ftype,metric,eps" + token_metric="iou" + token_eps="0.01" + token_pin_labels="0"> + + <element name="@NAME@" value="@VALUE@" ftype="@FTYPE@" compare="image_diff" metric="@METRIC@" eps="@EPS@" pin_labels="@PIN_LABELS@"> + <assert_contents> + <yield/> + </assert_contents> + </element> + + </xml> + + <xml + name="tests/intensity_image_diff/element" + tokens="name,value,ftype,metric,eps" + token_metric="rms" + token_eps="0.01"> + + <element name="@NAME@" value="@VALUE@" ftype="@FTYPE@" compare="image_diff" metric="@METRIC@" eps="@EPS@"> + <assert_contents> + <yield/> + </assert_contents> + </element> + + </xml> + +</macros>