From 8a730cb98f2d8a4b49125afd453098e2d3bded0e Mon Sep 17 00:00:00 2001 From: Leonid Kostrykin Date: Tue, 12 Mar 2024 22:11:27 +0100 Subject: [PATCH] Add `colorize_labels` tool Squashed commit of the following: commit 871c93fcb63929c5c7389d489bf52d086697f1c6 Author: Leonid Kostrykin Date: Tue Mar 12 21:09:03 2024 +0000 Fix UI commit 27030b7b1301440bc3bf1028c2f56bd1795bdc26 Author: Leonid Kostrykin Date: Tue Mar 12 21:49:40 2024 +0100 Fix commit 3fea4e4447c1a0da12bf49cb8d56a3469463c0f9 Author: Leonid Kostrykin Date: Tue Mar 12 20:42:43 2024 +0100 Fix commit b3f4c7b924b1b8e151f2302492e7e679630c84e5 Author: Leonid Kostrykin Date: Tue Mar 12 19:38:27 2024 +0000 Fix tool commit 2d67b6eca1ce6f96d05d3e9acb492cea24d16263 Author: Leonid Kostrykin Date: Tue Mar 12 19:35:14 2024 +0000 Fix tool commit 8b879d90f3ba0e655343172a438537e2895ffd67 Author: Leonid Kostrykin Date: Tue Mar 12 19:34:59 2024 +0000 Fix tool commit 8a6fcc247132307f0da7dacdd5eabb20b8e4a895 Author: Leonid Kostrykin Date: Tue Mar 12 19:32:50 2024 +0000 Fix tool commit 8494ae2cdce69692d950ed30e0eedc8516c8d020 Author: Leonid Kostrykin Date: Tue Mar 12 20:27:17 2024 +0100 Fix test commit 0dac5e4d384d9ba8d08082e6f070fa033f0ff456 Author: Leonid Kostrykin Date: Tue Mar 12 19:25:57 2024 +0000 Add help section commit ac979690303c42242d4b03611d094dea6c2f8317 Author: Leonid Kostrykin Date: Tue Mar 12 19:20:59 2024 +0000 Fix command commit dcfe3d00facb6e2718b5155e0b77610fb95ed2d2 Author: Leonid Kostrykin Date: Tue Mar 12 19:20:06 2024 +0000 Add tests commit 31f4a82f81aa81a21d85276987555677a4a1cc1f Author: Leonid Kostrykin Date: Tue Mar 12 19:03:08 2024 +0000 Add test data commit b0b82f14e610832caf6cbba55381231ba80d22cc Author: Leonid Kostrykin Date: Tue Mar 12 18:38:02 2024 +0000 wip commit 16f5ea788d510ff1c28add34aa401c3467214cc4 Author: Leonid Kostrykin Date: Tue Mar 12 18:19:26 2024 +0000 wip commit 5572a649006afb0d73df9665d3df8c74c079f642 Author: Leonid Kostrykin Date: Tue Mar 12 17:58:50 2024 +0000 Add .shed.yml commit 9b1b5d881100f2024c4c17ae04960e070023b6f3 Author: Leonid Kostrykin Date: Tue Mar 12 17:57:04 2024 +0000 Add `colorize_labels` tool --- tools/colorize_labels/.shed.yml | 8 +++ tools/colorize_labels/colorize_labels.py | 43 +++++++++++++ tools/colorize_labels/colorize_labels.xml | 64 ++++++++++++++++++++ tools/colorize_labels/test-data/input1.tif | Bin 0 -> 456 bytes tools/colorize_labels/test-data/output1.png | Bin 0 -> 110 bytes 5 files changed, 115 insertions(+) create mode 100644 tools/colorize_labels/.shed.yml create mode 100644 tools/colorize_labels/colorize_labels.py create mode 100644 tools/colorize_labels/colorize_labels.xml create mode 100644 tools/colorize_labels/test-data/input1.tif create mode 100644 tools/colorize_labels/test-data/output1.png diff --git a/tools/colorize_labels/.shed.yml b/tools/colorize_labels/.shed.yml new file mode 100644 index 00000000..40fb7b51 --- /dev/null +++ b/tools/colorize_labels/.shed.yml @@ -0,0 +1,8 @@ +categories: + - Imaging +description: Colorize label map +long_description: Colorize label map for visualization. +name: colorize_labels +owner: imgteam +homepage_url: https://github.com/bmcv +remote_repository_url: https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/colorize_labels \ No newline at end of file diff --git a/tools/colorize_labels/colorize_labels.py b/tools/colorize_labels/colorize_labels.py new file mode 100644 index 00000000..838a8600 --- /dev/null +++ b/tools/colorize_labels/colorize_labels.py @@ -0,0 +1,43 @@ +import argparse + +import numpy as np +import skimage.io +import skimage.util +import superdsm.render + + +def color_hex_to_rgb_tuple(hex): + if hex.startswith('#'): + hex = hex[1:] + return ( + int(hex[0:2], 16), + int(hex[2:4], 16), + int(hex[4:6], 16), + ) + + +if __name__ == '__main__': + + parser = argparse.ArgumentParser() + parser.add_argument('input', type=str) + parser.add_argument('--bg_label', type=int) + parser.add_argument('--bg_color', type=str) + parser.add_argument('--cmap', type=str, default='hsv') + parser.add_argument('--seed', type=int) + parser.add_argument('--output', type=str) + args = parser.parse_args() + + im = skimage.io.imread(args.input) + im = np.squeeze(im) + assert im.ndim == 2 + + im_colorized = superdsm.render.colorize_labels( + labels=im, + bg_label=args.bg_label, + cmap=args.cmap, + bg_color=np.divide(color_hex_to_rgb_tuple(args.bg_color), 255), + shuffle=args.seed, + ) + + im_colorized = skimage.util.img_as_ubyte(im_colorized) + skimage.io.imsave(args.output, im_colorized) diff --git a/tools/colorize_labels/colorize_labels.xml b/tools/colorize_labels/colorize_labels.xml new file mode 100644 index 00000000..b951b075 --- /dev/null +++ b/tools/colorize_labels/colorize_labels.xml @@ -0,0 +1,64 @@ + + with SuperDSM + + 0.2.0 + 0 + + + operation_3443 + + + superdsm + superdsm + + + superdsm + numpy + scikit-image + + + + + + + + + + + + + + + + + + + + + + Colorize a 2-D label map for visualization. + + Label maps are produced by segmentation and other image analysis steps. + Direct inspection of label maps can be difficult, + because labels usually correspond to gray values which are difficult to + distinguish visually from each other and from the image background. + To facilitate the visual inspection of label maps, this tools converts + label maps to color images, by assigning each label a unique color. + + + 10.1109/TPAMI.2022.3185583 + + diff --git a/tools/colorize_labels/test-data/input1.tif b/tools/colorize_labels/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}~Bq