Mercurial > repos > imgteam > concat_channels
changeset 0:30517f733f7b draft
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/concat_channels/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
author | imgteam |
---|---|
date | Sat, 09 Feb 2019 14:33:14 -0500 |
parents | |
children | d42501109c05 |
files | concat_channels.py concat_channels.xml test-data/out.tiff test-data/res.tiff test-data/sample1.png test-data/sample2.png |
diffstat | 6 files changed, 74 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/concat_channels.py Sat Feb 09 14:33:14 2019 -0500 @@ -0,0 +1,33 @@ +import argparse +import sys +import warnings +import numpy as np +import skimage.io +import skimage.util + +def concat_channels(input_image_paths, output_image_path, axis): + 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) + images.append(raw_image) + 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') + +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') + args = parser.parse_args() + + # print([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) + # concat_channels(args.input_files, args.out_file, args.axis)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/concat_channels.xml Sat Feb 09 14:33:14 2019 -0500 @@ -0,0 +1,41 @@ +<tool id="ip_concat_channels" name="Concatenate images" version="0.1"> + <description></description> + <requirements> + <requirement type="package" version="0.14.2">scikit-image</requirement> + <requirement type="package" version="1.15.4">numpy</requirement> + </requirements> + <command> + <![CDATA[ + python '$__tool_directory__/concat_channels.py' + #for $input in $inputs + '$input' + #end for + -o '$output' --axis '$axis' + ]]> + </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> + </inputs> + <outputs> + <data format="tiff" name="output"/> + </outputs> + <tests> + <test> + <param name="inputs" value="sample1.png,sample2.png"/> + <param name="axis" value="0"/> + <output name="output" value="res.tiff" ftype="tiff" compare="sim_size"/> + </test> + </tests> + <help> + **What it does** + + This tool concatenates images. + </help> + <citations> + <citation type="doi">10.1016/j.jbiotec.2017.07.019</citation> + </citations> +</tool>