# HG changeset patch # User imgteam # Date 1747037744 0 # Node ID 7f8102bdbfa1db46a4a09e01ac47d886423adaf5 # Parent 984358e43242b759cde2ef19bdef841955c8af8b planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/binary2labelimage/ commit 48df7d9c58fb88e472caeb4d4a1e14170d79b643 diff -r 984358e43242 -r 7f8102bdbfa1 2d_split_binaryimage_by_watershed.py --- a/2d_split_binaryimage_by_watershed.py Tue Nov 14 08:27:27 2023 +0000 +++ b/2d_split_binaryimage_by_watershed.py Mon May 12 08:15:44 2025 +0000 @@ -1,11 +1,12 @@ import argparse import sys +import numpy as np import skimage.io import skimage.util from scipy import ndimage as ndi from skimage.feature import peak_local_max -from skimage.morphology import watershed +from skimage.segmentation import watershed if __name__ == "__main__": @@ -17,11 +18,15 @@ img_in = skimage.io.imread(args.input_file.name) distance = ndi.distance_transform_edt(img_in) - local_maxi = peak_local_max(distance, - indices=False, - min_distance=args.min_distance, - labels=img_in) - markers = ndi.label(local_maxi)[0] + + local_max_indices = peak_local_max( + distance, + min_distance=args.min_distance, + labels=img_in, + ) + local_max_mask = np.zeros(img_in.shape, dtype=bool) + local_max_mask[tuple(local_max_indices.T)] = True + markers = ndi.label(local_max_mask)[0] res = watershed(-distance, markers, mask=img_in) res = skimage.util.img_as_uint(res) diff -r 984358e43242 -r 7f8102bdbfa1 binary2label.py --- a/binary2label.py Tue Nov 14 08:27:27 2023 +0000 +++ b/binary2label.py Mon May 12 08:15:44 2025 +0000 @@ -1,19 +1,27 @@ import argparse -import sys + +import giatools +import scipy.ndimage as ndi +import tifffile -import skimage.io -import skimage.util -from PIL import Image -from skimage.measure import label +# Parse CLI parameters parser = argparse.ArgumentParser() -parser.add_argument('input_file', type=argparse.FileType('r'), default=sys.stdin, help='input file') -parser.add_argument('out_file', type=argparse.FileType('w'), default=sys.stdin, help='out file (TIFF)') +parser.add_argument('input', type=str, help='input file') +parser.add_argument('output', type=str, help='output file (TIFF)') args = parser.parse_args() -img_in = skimage.io.imread(args.input_file.name) > 0 -res = label(img_in) -res = skimage.util.img_as_uint(res) +# Read the input image with the original axes +img = giatools.Image.read(args.input) +img = img.normalize_axes_like( + img.original_axes, +) -res = Image.fromarray(res) -res.save(args.out_file.name, "tiff") +# Make sure the image is truly binary +img_arr_bin = (img.data > 0) + +# Perform the labeling +img.data = ndi.label(img_arr_bin)[0] + +# Write the result image (same axes as input image) +tifffile.imwrite(args.output, img.data, metadata=dict(axes=img.axes)) diff -r 984358e43242 -r 7f8102bdbfa1 binary2label.xml --- a/binary2label.xml Tue Nov 14 08:27:27 2023 +0000 +++ b/binary2label.xml Mon May 12 08:15:44 2025 +0000 @@ -1,9 +1,13 @@ - + - 0.5 + creators.xml + 0.6 0 + + + operation_3443 @@ -11,11 +15,8 @@ galaxy_image_analysis - scikit-image - tifffile - numpy - pillow - scipy + giatools + scipy - + @@ -45,19 +46,32 @@ - + - + - + - + + + + + + + + + + + + + + diff -r 984358e43242 -r 7f8102bdbfa1 creators.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/creators.xml Mon May 12 08:15:44 2025 +0000 @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -r 984358e43242 -r 7f8102bdbfa1 test-data/galaxyIcon_noText.tif Binary file test-data/galaxyIcon_noText.tif has changed diff -r 984358e43242 -r 7f8102bdbfa1 test-data/galaxyIcon_noText.tiff Binary file test-data/galaxyIcon_noText.tiff has changed diff -r 984358e43242 -r 7f8102bdbfa1 test-data/in.tif Binary file test-data/in.tif has changed diff -r 984358e43242 -r 7f8102bdbfa1 test-data/in.tiff Binary file test-data/in.tiff has changed diff -r 984358e43242 -r 7f8102bdbfa1 test-data/label.tif Binary file test-data/label.tif has changed diff -r 984358e43242 -r 7f8102bdbfa1 test-data/label.tiff Binary file test-data/label.tiff has changed diff -r 984358e43242 -r 7f8102bdbfa1 test-data/out.tif Binary file test-data/out.tif has changed diff -r 984358e43242 -r 7f8102bdbfa1 test-data/out.tiff Binary file test-data/out.tiff has changed diff -r 984358e43242 -r 7f8102bdbfa1 test-data/uint8_z12_x11_y10-output.tiff Binary file test-data/uint8_z12_x11_y10-output.tiff has changed diff -r 984358e43242 -r 7f8102bdbfa1 test-data/uint8_z12_x11_y10.tiff Binary file test-data/uint8_z12_x11_y10.tiff has changed