From 7f01644e3e47e320bdd9d8c1834de4aec82b0ce9 Mon Sep 17 00:00:00 2001 From: Leonid Kostrykin Date: Wed, 13 Mar 2024 14:42:27 +0100 Subject: [PATCH 1/2] Add `label_to_binary` tool Squashed commit of the following: commit 8b2f0909498b4067c5c767a21d129d9f23c610d0 Author: Leonid Kostrykin Date: Wed Mar 13 13:39:20 2024 +0000 Fix commit baf90b1dd0e87ba3be55800f868abc962aaabdbe Author: Leonid Kostrykin Date: Wed Mar 13 13:37:29 2024 +0000 Fix commit 4fd1accfa6271ded8f073ce41d83157d8e304203 Author: Leonid Kostrykin Date: Wed Mar 13 13:29:39 2024 +0000 Fix commit 58987c434064fa07e8cd48a07764312e128f9e6c Author: Leonid Kostrykin Date: Wed Mar 13 13:20:27 2024 +0000 Fix requirements commit 97e2339970c503b769f691d5b0dc89330ae5a7d3 Author: Leonid Kostrykin Date: Wed Mar 13 13:14:34 2024 +0000 Add output commit 43a9aedddc4c4357da7eadb2616e146051de158a Author: Leonid Kostrykin Date: Wed Mar 13 13:11:02 2024 +0000 Fix versions commit 601e1812379b3df2aedeadb93ebbafb6e74c4bd4 Author: Leonid Kostrykin Date: Wed Mar 13 13:07:47 2024 +0000 Fix commit e1616e428a0dc2bce5efa8fb8fab169bf0c140f4 Author: Leonid Kostrykin Date: Wed Mar 13 13:04:33 2024 +0000 Fix commit c0d79a6362ef3cf1e4da37f8405de81dc8424201 Author: Leonid Kostrykin Date: Wed Mar 13 12:54:38 2024 +0000 Add `label_to_binary` tool --- tools/label_to_binary/.shed.yml | 8 +++ tools/label_to_binary/label_to_binary.py | 18 +++++++ tools/label_to_binary/label_to_binary.xml | 54 ++++++++++++++++++++ tools/label_to_binary/test-data/input1.tif | Bin 0 -> 456 bytes tools/label_to_binary/test-data/output1.tif | Bin 0 -> 281 bytes 5 files changed, 80 insertions(+) create mode 100644 tools/label_to_binary/.shed.yml create mode 100644 tools/label_to_binary/label_to_binary.py create mode 100644 tools/label_to_binary/label_to_binary.xml create mode 100644 tools/label_to_binary/test-data/input1.tif create mode 100644 tools/label_to_binary/test-data/output1.tif diff --git a/tools/label_to_binary/.shed.yml b/tools/label_to_binary/.shed.yml new file mode 100644 index 00000000..d7bcc4a5 --- /dev/null +++ b/tools/label_to_binary/.shed.yml @@ -0,0 +1,8 @@ +categories: + - Imaging +description: Convert label map to binary image +long_description: This tools converts a label map (objects labeled by different labels/values) to a binary image. +name: label_to_binary +owner: imgteam +homepage_url: https://github.com/bmcv +remote_repository_url: https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/label_to_binary/ diff --git a/tools/label_to_binary/label_to_binary.py b/tools/label_to_binary/label_to_binary.py new file mode 100644 index 00000000..94b712cf --- /dev/null +++ b/tools/label_to_binary/label_to_binary.py @@ -0,0 +1,18 @@ +import argparse + +import numpy as np +import skimage.io + + +if __name__ == '__main__': + + parser = argparse.ArgumentParser() + parser.add_argument('input', type=str) + parser.add_argument('bg_label', type=int) + parser.add_argument('output', type=str) + args = parser.parse_args() + + im = skimage.io.imread(args.input) + im = (im != args.bg_label) + im = (im * 255).astype(np.uint8) + skimage.io.imsave(args.output, im) diff --git a/tools/label_to_binary/label_to_binary.xml b/tools/label_to_binary/label_to_binary.xml new file mode 100644 index 00000000..8b729fd4 --- /dev/null +++ b/tools/label_to_binary/label_to_binary.xml @@ -0,0 +1,54 @@ + + with NumPy + + 1.26.4 + 0 + + + operation_3443 + + + galaxy_image_analysis + + + numpy + scikit-image + + + + + + + + + + + + + + + + + + + This tools converts a label map (objects labeled by different labels/values) to a binary image. + + The input image is converted by assigning white (pixel value 255) to image regions corresponding to labeled objects, + and black (pixel value 0) to image regions corresponding to image background (by default, this is label 0). + + + 10.1038/s41586-020-2649-2 + + diff --git a/tools/label_to_binary/test-data/input1.tif b/tools/label_to_binary/test-data/input1.tif new file mode 100644 index 0000000000000000000000000000000000000000..d19d6682f98714ecb15c9afc9c94d835e1be8502 GIT binary patch literal 456 zcmebD)MDUZU|`^9U|?inU<9&QftV4A&BVwI7Iy%OGeg-Rb!i16@Dg2KL`+_A*zTcVZMOT%uuZ` L8kb2hc^C}R Date: Wed, 13 Mar 2024 15:21:57 +0100 Subject: [PATCH 2/2] add profile --- tools/label_to_binary/label_to_binary.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/label_to_binary/label_to_binary.xml b/tools/label_to_binary/label_to_binary.xml index 8b729fd4..9d1dedd1 100644 --- a/tools/label_to_binary/label_to_binary.xml +++ b/tools/label_to_binary/label_to_binary.xml @@ -1,4 +1,4 @@ - + with NumPy 1.26.4