Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add label_to_binary tool #114

Merged
merged 2 commits into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions tools/label_to_binary/.shed.yml
Original file line number Diff line number Diff line change
@@ -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/
18 changes: 18 additions & 0 deletions tools/label_to_binary/label_to_binary.py
Original file line number Diff line number Diff line change
@@ -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)
54 changes: 54 additions & 0 deletions tools/label_to_binary/label_to_binary.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<tool id="label_to_binary" name="Convert label map to binary image" version="@TOOL_VERSION@+galaxy@VERSION_SUFFIX@" profile="22.05">
<description>with NumPy</description>
<macros>
<token name="@TOOL_VERSION@">1.26.4</token>
<token name="@VERSION_SUFFIX@">0</token>
</macros>
<edam_operations>
<edam_operation>operation_3443</edam_operation>
</edam_operations>
<xrefs>
<xref type="bio.tools">galaxy_image_analysis</xref>
</xrefs>
<requirements>
<requirement type="package" version="1.26.4">numpy</requirement>
<requirement type="package" version="0.18.1">scikit-image</requirement>
</requirements>
<command><![CDATA[

## Inputs

python '$__tool_directory__/label_to_binary.py'
'$input'
'$bg_label'

## Outputs

./output.tif

]]>
</command>
<inputs>
<param name="input" type="data" format="tiff,png" label="Input image (label map)" />
<param argument="--bg_label" type="integer" value="0" label="Background label" />
</inputs>
<outputs>
<data format="tiff" name="output" from_work_dir="output.tif" />
</outputs>
<tests>
<test>
<param name="input" value="input1.tif" />
<param name="bg_label" value="0" />
<output name="output" value="output1.tif" ftype="tiff" compare="sim_size" delta_frac="0.1"/>
</test>
</tests>
<help>
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).
</help>
<citations>
<citation type="doi">10.1038/s41586-020-2649-2</citation>
</citations>
</tool>
Binary file added tools/label_to_binary/test-data/input1.tif
Binary file not shown.
Binary file added tools/label_to_binary/test-data/output1.tif
Binary file not shown.