Mercurial > repos > imgteam > 2d_split_binaryimage_by_watershed
changeset 0:5e21d7342593 draft
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/2d_split_binaryimage_by_watershed/ commit b2acc1845a25828181597fe5b6982fe116a7796d
author | imgteam |
---|---|
date | Mon, 22 Jul 2019 05:00:37 -0400 |
parents | |
children | f8f7987586b7 |
files | 2d_split_binaryimage_by_watershed.py 2d_split_binaryimage_by_watershed.xml test-data/in.tif test-data/out.tif |
diffstat | 4 files changed, 61 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/2d_split_binaryimage_by_watershed.py Mon Jul 22 05:00:37 2019 -0400 @@ -0,0 +1,26 @@ +import argparse +import sys +import skimage.io +from skimage.morphology import watershed +from skimage.feature import peak_local_max +from scipy import ndimage as ndi +import skimage.util + +if __name__ == "__main__": + parser = argparse.ArgumentParser(description='Split binaryimage by watershed') + parser.add_argument('input_file', type=argparse.FileType('r'), default=sys.stdin, help='input file') + parser.add_argument('out_file', type=argparse.FileType('w'), default=sys.stdin, help='out file (TIFF)') + parser.add_argument('min_distance', type=int, default=100, help='Minimum distance to next object') + args = parser.parse_args() + + img_in = skimage.io.imread(args.input_file.name) + distance = ndi.distance_transform_edt(img_in) + local_maxi = peak_local_max(distance, + indices=False, + min_distance=args.min_distance, + labels=img_in) + markers = ndi.label(local_maxi)[0] + res = watershed(-distance, markers, mask=img_in) + + res = skimage.util.img_as_uint(res) + skimage.io.imsave(args.out_file.name, res, plugin="tifffile")
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/2d_split_binaryimage_by_watershed.xml Mon Jul 22 05:00:37 2019 -0400 @@ -0,0 +1,35 @@ +<tool id="ip_2d_split_binaryimage_by_watershed" name="Split objects" version="0.0.1"> + <description>Split binary image by using watershed</description> + <requirements> + <requirement type="package" version="0.14.2">scikit-image</requirement> + <requirement type="package" version="1.15.4">numpy</requirement> + <requirement type="package" version="5.3.0">pillow</requirement> + <requirement type="package" version="0.15.1">tifffile</requirement> + <requirement type="package" version="1.2.1">scipy</requirement> + </requirements> + <command detect_errors="aggressive"> + <![CDATA[ + python '$__tool_directory__/2d_split_binaryimage_by_watershed.py' '$input' '$output' $min_distance + ]]> + </command> + <inputs> + <param name="input" type="data" format="tiff" label="Source file" /> + <param name="min_distance" type="integer" value="5" label="Minimum distance between two objects." /> + </inputs> + <outputs> + <data format="tiff" name="output" /> + </outputs> + <tests> + <test> + <param name="input" value="in.tif"/> + <output name="output" value="out.tif" ftype="tiff" compare="sim_size"/> + <param name="min_distance" value="10"/> + </test> + </tests> + <help> + Split binary image by using distance transform and watershed. + </help> + <citations> + <citation type="doi">10.1016/j.jbiotec.2017.07.019</citation> + </citations> +</tool>