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 00000000..d19d6682 Binary files /dev/null and b/tools/colorize_labels/test-data/input1.tif differ diff --git a/tools/colorize_labels/test-data/output1.png b/tools/colorize_labels/test-data/output1.png new file mode 100644 index 00000000..b39c85a3 Binary files /dev/null and b/tools/colorize_labels/test-data/output1.png differ