# HG changeset patch # User imgteam # Date 1699950447 0 # Node ID 984358e43242b759cde2ef19bdef841955c8af8b # Parent 9bb446db4a1e079c218bbabbd7a1314552f3e103 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/binary2labelimage/ commit 00199464fa2aa1928a49e2379edf199c3db91533 diff -r 9bb446db4a1e -r 984358e43242 2d_split_binaryimage_by_watershed.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/2d_split_binaryimage_by_watershed.py Tue Nov 14 08:27:27 2023 +0000 @@ -0,0 +1,28 @@ +import argparse +import sys + +import skimage.io +import skimage.util +from scipy import ndimage as ndi +from skimage.feature import peak_local_max +from skimage.morphology import watershed + + +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") diff -r 9bb446db4a1e -r 984358e43242 binary2label.xml --- a/binary2label.xml Mon Nov 13 22:10:33 2023 +0000 +++ b/binary2label.xml Tue Nov 14 08:27:27 2023 +0000 @@ -1,5 +1,9 @@ - + + + 0.5 + 0 + operation_3443 @@ -7,16 +11,34 @@ galaxy_image_analysis - scikit-image + scikit-image tifffile + numpy + pillow + scipy - + + + + + + + + + + + + @@ -24,13 +46,24 @@ + + + + + + + + + + + - **What it does** + This tool assigns each object a unique label. - This tool assigns every object an own grey value. + Individual objects are determined using connected component analysis, or distance transform and watershed. 10.1016/j.jbiotec.2017.07.019 diff -r 9bb446db4a1e -r 984358e43242 test-data/in.tif Binary file test-data/in.tif has changed diff -r 9bb446db4a1e -r 984358e43242 test-data/out.tif Binary file test-data/out.tif has changed