view voronoi_tessellation.py @ 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 412d7478ec92
line wrap: on
line source

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)