Mercurial > repos > imgteam > voronoi_tesselation
comparison 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 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:8b74843c136e |
---|---|
1 import argparse | |
2 | |
3 import numpy as np | |
4 import scipy.ndimage as ndi | |
5 import skimage.io | |
6 from skimage.segmentation import watershed | |
7 | |
8 | |
9 if __name__ == '__main__': | |
10 | |
11 parser = argparse.ArgumentParser() | |
12 parser.add_argument('input') | |
13 parser.add_argument('output') | |
14 args = parser.parse_args() | |
15 | |
16 im = skimage.io.imread(args.input) | |
17 im = im.squeeze() | |
18 assert im.ndim == 2 | |
19 | |
20 distances = np.full(im.shape, np.inf) | |
21 for label in np.unique(im): | |
22 if label == 0: | |
23 continue | |
24 | |
25 label_distances = ndi.distance_transform_edt(im != label) | |
26 distances = np.min((distances, label_distances), axis=0) | |
27 | |
28 result = watershed( | |
29 image=distances, | |
30 markers=im, | |
31 ) | |
32 | |
33 skimage.io.imsave(args.output, result) |