Skip to content

Commit

Permalink
Add colorize_labels tool
Browse files Browse the repository at this point in the history
Squashed commit of the following:

commit 871c93f
Author: Leonid Kostrykin <[email protected]>
Date:   Tue Mar 12 21:09:03 2024 +0000

    Fix UI

commit 27030b7
Author: Leonid Kostrykin <[email protected]>
Date:   Tue Mar 12 21:49:40 2024 +0100

    Fix

commit 3fea4e4
Author: Leonid Kostrykin <[email protected]>
Date:   Tue Mar 12 20:42:43 2024 +0100

    Fix

commit b3f4c7b
Author: Leonid Kostrykin <[email protected]>
Date:   Tue Mar 12 19:38:27 2024 +0000

    Fix tool

commit 2d67b6e
Author: Leonid Kostrykin <[email protected]>
Date:   Tue Mar 12 19:35:14 2024 +0000

    Fix tool

commit 8b879d9
Author: Leonid Kostrykin <[email protected]>
Date:   Tue Mar 12 19:34:59 2024 +0000

    Fix tool

commit 8a6fcc2
Author: Leonid Kostrykin <[email protected]>
Date:   Tue Mar 12 19:32:50 2024 +0000

    Fix tool

commit 8494ae2
Author: Leonid Kostrykin <[email protected]>
Date:   Tue Mar 12 20:27:17 2024 +0100

    Fix test

commit 0dac5e4
Author: Leonid Kostrykin <[email protected]>
Date:   Tue Mar 12 19:25:57 2024 +0000

    Add help section

commit ac97969
Author: Leonid Kostrykin <[email protected]>
Date:   Tue Mar 12 19:20:59 2024 +0000

    Fix command

commit dcfe3d0
Author: Leonid Kostrykin <[email protected]>
Date:   Tue Mar 12 19:20:06 2024 +0000

    Add tests

commit 31f4a82
Author: Leonid Kostrykin <[email protected]>
Date:   Tue Mar 12 19:03:08 2024 +0000

    Add test data

commit b0b82f1
Author: Leonid Kostrykin <[email protected]>
Date:   Tue Mar 12 18:38:02 2024 +0000

    wip

commit 16f5ea7
Author: Leonid Kostrykin <[email protected]>
Date:   Tue Mar 12 18:19:26 2024 +0000

    wip

commit 5572a64
Author: Leonid Kostrykin <[email protected]>
Date:   Tue Mar 12 17:58:50 2024 +0000

    Add .shed.yml

commit 9b1b5d8
Author: Leonid Kostrykin <[email protected]>
Date:   Tue Mar 12 17:57:04 2024 +0000

    Add `colorize_labels` tool
  • Loading branch information
kostrykin committed Mar 12, 2024
1 parent fa4501f commit 8a730cb
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 0 deletions.
8 changes: 8 additions & 0 deletions tools/colorize_labels/.shed.yml
Original file line number Diff line number Diff line change
@@ -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
43 changes: 43 additions & 0 deletions tools/colorize_labels/colorize_labels.py
Original file line number Diff line number Diff line change
@@ -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)
64 changes: 64 additions & 0 deletions tools/colorize_labels/colorize_labels.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<tool id="colorize_labels" name="Colorize label map" version="@TOOL_VERSION@+galaxy@VERSION_SUFFIX@" profile="20.05">
<description>with SuperDSM</description>
<macros>
<token name="@TOOL_VERSION@">0.2.0</token>
<token name="@VERSION_SUFFIX@">0</token>
</macros>
<edam_operations>
<edam_operation>operation_3443</edam_operation>
</edam_operations>
<xrefs>
<xref type="bio.tools">superdsm</xref>
<xref type="biii">superdsm</xref>
</xrefs>
<requirements>
<requirement type="package" version="0.2.0">superdsm</requirement>
<requirement type="package" version="1.20">numpy</requirement>
<requirement type="package" version="0.18.1">scikit-image</requirement>
</requirements>
<command><![CDATA[
## Inputs
python '$__tool_directory__/colorize_labels.py' '$input'
--seed $seed
--bg_label $bg_label
--bg_color '$bg_color'
## Outputs
--output output.png
]]>
</command>
<inputs>
<param name="input" type="data" format="tiff,png" label="Input image (label map)" />
<param argument="--seed" type="integer" value="0" label="Randomization seed" />
<param argument="--bg_label" type="integer" value="0" label="Background label" />
<param argument="--bg_color" type="color" value="#000000" label="Background color"/>
</inputs>
<outputs>
<data format="png" name="output" from_work_dir="output.png" />
</outputs>
<tests>
<test>
<param name="input" value="input1.tif"/>
<param name="bg_label" value="0"/>
<param name="bg_color" value="#5a5a5a"/>
<output name="output" value="output1.png" ftype="png" compare="sim_size" delta_frac="0.1"/>
</test>
</tests>
<help>
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.
</help>
<citations>
<citation type="doi">10.1109/TPAMI.2022.3185583</citation>
</citations>
</tool>
Binary file added tools/colorize_labels/test-data/input1.tif
Binary file not shown.
Binary file added tools/colorize_labels/test-data/output1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 8a730cb

Please sign in to comment.