changeset 0:1b0fc671187f draft

planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/superdsm/ commit 4d66ff6e8a2a842e44e8d0d7102dfb3ac78dca7e
author imgteam
date Sun, 25 Jun 2023 21:48:40 +0000
parents
children 700ae37e5c69
files run-superdsm.py superdsm.xml test-data/BBBC033_C2_z28.png test-data/overlay.png
diffstat 4 files changed, 111 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/run-superdsm.py	Sun Jun 25 21:48:40 2023 +0000
@@ -0,0 +1,63 @@
+"""
+Copyright 2023 Leonid Kostrykin, Biomedical Computer Vision Group, Heidelberg University.
+
+Distributed under the MIT license.
+See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
+
+"""
+
+import argparse
+import imghdr
+import os
+import pathlib
+import shutil
+import tempfile
+
+import ray
+import superdsm.automation
+import superdsm.io
+import superdsm.render
+
+
+if __name__ == "__main__":
+    parser = argparse.ArgumentParser(description='Segmentation of cell nuclei in 2-D fluorescence microscopy images')
+    parser.add_argument('image', help='Path to the input image')
+    parser.add_argument('cfg', help='Path to the file containing the configuration')
+    parser.add_argument('masks', help='Path to the file containing the segmentation masks')
+    parser.add_argument('overlay', help='Path to the file containing the overlay of the segmentation results')
+    parser.add_argument('seg_border', type=int)
+    parser.add_argument('slots', type=int)
+    args = parser.parse_args()
+
+    if args.slots >= 2:
+        num_threads_per_process = 2
+        num_processes = args.slots // num_threads_per_process
+    else:
+        num_threads_per_process = 1
+        num_processes = 1
+
+    os.environ['MKL_NUM_THREADS'] = str(num_threads_per_process)
+    os.environ['OPENBLAS_NUM_THREADS'] = str(num_threads_per_process)
+    os.environ['MKL_DEBUG_CPU_TYPE'] = '5'
+
+    ray.init(num_cpus=num_processes, log_to_driver=True)
+
+    with tempfile.TemporaryDirectory() as tmpdirname:
+        tmpdir = pathlib.Path(tmpdirname)
+        img_ext = imghdr.what(args.image)
+        img_filepath = tmpdir / f'input.{img_ext}'
+        shutil.copy(str(args.image), img_filepath)
+
+        pipeline = superdsm.pipeline.create_default_pipeline()
+        cfg = superdsm.config.Config()
+        img = superdsm.io.imread(img_filepath)
+        data, cfg, _ = superdsm.automation.process_image(pipeline, cfg, img)
+
+        with open(args.cfg, 'w') as fp:
+            cfg.dump_json(fp)
+
+        overlay = superdsm.render.render_result_over_image(data, border_width=args.seg_border, normalize_img=False)
+        superdsm.io.imwrite(args.overlay, overlay)
+
+        masks = superdsm.render.rasterize_labels(data)
+        superdsm.io.imwrite(args.masks, masks)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/superdsm.xml	Sun Jun 25 21:48:40 2023 +0000
@@ -0,0 +1,48 @@
+<tool id="ip_superdsm" name="SuperDSM" version="0.1.2-1" profile="20.05">
+   <description>globally optimal segmentation method based on superadditivity and deformable shape models for cell nuclei in fluorescence microscopy images</description>
+   <requirements> 
+        <requirement type="package" version="0.1.2">superdsm</requirement>
+        <requirement type="package" version="1.6.0">ray-core</requirement>
+        <requirement type="package" version="0.18.1">scikit-image</requirement>
+   </requirements>
+   <command detect_errors="aggressive">
+   <![CDATA[
+   python '$__tool_directory__/run-superdsm.py'
+   '${dataset}'
+   'cfg.json'
+   'masks.png'
+   'overlay.png'
+   $seg_border
+   \${GALAXY_SLOTS:-4}
+   > stdout.txt
+   ]]>
+   </command>
+   <inputs>
+        <param name="dataset" type="data" format="tiff,png" label="Dataset" />
+        <param name="seg_border" type="integer" min="1" value="8" label="Width of the outlines (in pixels) of the segmentation results (overlays)" />
+        <!--
+        <section name="config" title="Hyperparameters" expanded="false">
+        </section>
+        -->
+    </inputs>
+    <outputs>
+        <data format="txt" name="stdout" from_work_dir="stdout.txt" label="${tool.name} on ${on_string}: stdout" />
+        <data format="json" name="cfg" from_work_dir="cfg.json" label="${tool.name} on ${on_string}: cfg" />
+        <data format="png" name="masks" from_work_dir="masks.png" label="${tool.name} on ${on_string}: masks" />
+        <data format="png" name="overlay" from_work_dir="overlay.png" label="${tool.name} on ${on_string}: overlay" />
+    </outputs>
+    <tests>
+        <test>
+            <param name="dataset" value="BBBC033_C2_z28.png" />
+            <output name="overlay" value="overlay.png" ftype="png" compare="sim_size" />
+        </test>
+    </tests>
+    <help>
+        This tool permits the segmentation of cell nuclei in 2-D fluorescence microscopy images.
+
+        You can either use an individual input image (PNG, TIF) or a collection of such images.
+    </help>
+    <citations>
+        <citation type="doi">10.1109/TPAMI.2022.3185583</citation>
+    </citations>
+</tool>
Binary file test-data/BBBC033_C2_z28.png has changed
Binary file test-data/overlay.png has changed