Mercurial > repos > imgteam > voronoi_tesselation
changeset 0:8b74843c136e draft
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/voronoi_tesselation commit 43f036ed5341c36a1e076f9df9f47a3743ef4e6f
author | imgteam |
---|---|
date | Sat, 09 Mar 2024 22:27:23 +0000 |
parents | |
children | e7fdea8385f0 |
files | test-data/input1.tiff test-data/input1_result.tiff voronoi_tessellation.py voronoi_tessellation.xml |
diffstat | 4 files changed, 86 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/voronoi_tessellation.py Sat Mar 09 22:27:23 2024 +0000 @@ -0,0 +1,33 @@ +import argparse + +import numpy as np +import scipy.ndimage as ndi +import skimage.io +from skimage.segmentation import watershed + + +if __name__ == '__main__': + + parser = argparse.ArgumentParser() + parser.add_argument('input') + parser.add_argument('output') + args = parser.parse_args() + + im = skimage.io.imread(args.input) + im = im.squeeze() + assert im.ndim == 2 + + distances = np.full(im.shape, np.inf) + for label in np.unique(im): + if label == 0: + continue + + label_distances = ndi.distance_transform_edt(im != label) + distances = np.min((distances, label_distances), axis=0) + + result = watershed( + image=distances, + markers=im, + ) + + skimage.io.imsave(args.output, result)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/voronoi_tessellation.xml Sat Mar 09 22:27:23 2024 +0000 @@ -0,0 +1,53 @@ +<tool id="voronoi_tessellation" name="Compute Voronoi tessellation" version="@TOOL_VERSION@+galaxy@VERSION_SUFFIX@" profile="23.0"> + <description>with scikit-image</description> + <macros> + <token name="@TOOL_VERSION@">0.22.0</token> + <token name="@VERSION_SUFFIX@">0</token> + </macros> + <edam_operations> + <edam_operation>operation_3443</edam_operation> + </edam_operations> + <xrefs> + <xref type="bio.tools">scikit-image</xref> + <xref type="biii">scikit-image</xref> + </xrefs> + <requirements> + <requirement type="package" version="1.26.4">numpy</requirement> + <requirement type="package" version="1.12.0">scipy</requirement> + <requirement type="package" version="0.22.0">scikit-image</requirement> + </requirements> + <command><![CDATA[ + + ## Inputs + + python '$__tool_directory__/voronoi_tessellation.py' '$input' + + ## Outputs + + ./result.tiff + + ]]> + </command> + <inputs> + <param name="input" type="data" format="png,tiff" label="Labeled image" /> + </inputs> + <outputs> + <data format="tiff" name="result" from_work_dir="result.tiff" /> + </outputs> + <tests> + <test> + <param name="input" value="input1.tiff" /> + <output name="result" value="input1_result.tiff" ftype="tiff" compare="sim_size" delta="0" /> + </test> + </tests> + <help> + + This tool computes Voronoi tessellations for labeled images. + Voronoi tessellations are also known as Vornoi diagrams, or Dirichlet tessellations. + Zero labels are treated as image background. + + </help> + <citations> + <citation type="doi">10.7717/peerj.453</citation> + </citations> +</tool>