Mercurial > repos > imgteam > binary2labelimage
view binary2label.py @ 3:a041e4e9d449 draft default tip
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/binary2labelimage/ commit 48df7d9c58fb88e472caeb4d4a1e14170d79b643
author | imgteam |
---|---|
date | Mon, 12 May 2025 08:15:32 +0000 |
parents | 938e2358eb80 |
children |
line wrap: on
line source
import argparse import giatools import scipy.ndimage as ndi import tifffile # Parse CLI parameters parser = argparse.ArgumentParser() parser.add_argument('input', type=str, help='input file') parser.add_argument('output', type=str, help='output file (TIFF)') args = parser.parse_args() # Read the input image with the original axes img = giatools.Image.read(args.input) img = img.normalize_axes_like( img.original_axes, ) # 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))