# HG changeset patch # User imgteam # Date 1710284445 0 # Node ID 0afb17e107ffa9fdd155e48f8e4d9dde26fdfd49 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/colorize_labels commit ffedf4e17ecbb226657ccf8472b0572532e9aa8a diff -r 000000000000 -r 0afb17e107ff colorize_labels.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/colorize_labels.py Tue Mar 12 23:00:45 2024 +0000 @@ -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 -r 000000000000 -r 0afb17e107ff colorize_labels.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/colorize_labels.xml Tue Mar 12 23:00:45 2024 +0000 @@ -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 -r 000000000000 -r 0afb17e107ff test-data/input1.tif Binary file test-data/input1.tif has changed diff -r 000000000000 -r 0afb17e107ff test-data/output1.png Binary file test-data/output1.png has changed