Mercurial > repos > imgteam > voronoi_tesselation
annotate voronoi_tessellation.py @ 2:412d7478ec92 draft
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/voronoi_tesselation commit c86a1b93cb7732f7331a981d13465653cc1a2790
author | imgteam |
---|---|
date | Wed, 24 Apr 2024 08:13:41 +0000 |
parents | 8b74843c136e |
children |
rev | line source |
---|---|
0
8b74843c136e
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/voronoi_tesselation commit 43f036ed5341c36a1e076f9df9f47a3743ef4e6f
imgteam
parents:
diff
changeset
|
1 import argparse |
8b74843c136e
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/voronoi_tesselation commit 43f036ed5341c36a1e076f9df9f47a3743ef4e6f
imgteam
parents:
diff
changeset
|
2 |
2
412d7478ec92
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/voronoi_tesselation commit c86a1b93cb7732f7331a981d13465653cc1a2790
imgteam
parents:
0
diff
changeset
|
3 import giatools.io |
0
8b74843c136e
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/voronoi_tesselation commit 43f036ed5341c36a1e076f9df9f47a3743ef4e6f
imgteam
parents:
diff
changeset
|
4 import numpy as np |
8b74843c136e
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/voronoi_tesselation commit 43f036ed5341c36a1e076f9df9f47a3743ef4e6f
imgteam
parents:
diff
changeset
|
5 import scipy.ndimage as ndi |
8b74843c136e
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/voronoi_tesselation commit 43f036ed5341c36a1e076f9df9f47a3743ef4e6f
imgteam
parents:
diff
changeset
|
6 import skimage.io |
8b74843c136e
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/voronoi_tesselation commit 43f036ed5341c36a1e076f9df9f47a3743ef4e6f
imgteam
parents:
diff
changeset
|
7 from skimage.segmentation import watershed |
8b74843c136e
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/voronoi_tesselation commit 43f036ed5341c36a1e076f9df9f47a3743ef4e6f
imgteam
parents:
diff
changeset
|
8 |
8b74843c136e
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/voronoi_tesselation commit 43f036ed5341c36a1e076f9df9f47a3743ef4e6f
imgteam
parents:
diff
changeset
|
9 |
8b74843c136e
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/voronoi_tesselation commit 43f036ed5341c36a1e076f9df9f47a3743ef4e6f
imgteam
parents:
diff
changeset
|
10 if __name__ == '__main__': |
8b74843c136e
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/voronoi_tesselation commit 43f036ed5341c36a1e076f9df9f47a3743ef4e6f
imgteam
parents:
diff
changeset
|
11 |
8b74843c136e
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/voronoi_tesselation commit 43f036ed5341c36a1e076f9df9f47a3743ef4e6f
imgteam
parents:
diff
changeset
|
12 parser = argparse.ArgumentParser() |
8b74843c136e
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/voronoi_tesselation commit 43f036ed5341c36a1e076f9df9f47a3743ef4e6f
imgteam
parents:
diff
changeset
|
13 parser.add_argument('input') |
8b74843c136e
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/voronoi_tesselation commit 43f036ed5341c36a1e076f9df9f47a3743ef4e6f
imgteam
parents:
diff
changeset
|
14 parser.add_argument('output') |
8b74843c136e
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/voronoi_tesselation commit 43f036ed5341c36a1e076f9df9f47a3743ef4e6f
imgteam
parents:
diff
changeset
|
15 args = parser.parse_args() |
8b74843c136e
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/voronoi_tesselation commit 43f036ed5341c36a1e076f9df9f47a3743ef4e6f
imgteam
parents:
diff
changeset
|
16 |
2
412d7478ec92
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/voronoi_tesselation commit c86a1b93cb7732f7331a981d13465653cc1a2790
imgteam
parents:
0
diff
changeset
|
17 im = giatools.io.imread(args.input) |
0
8b74843c136e
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/voronoi_tesselation commit 43f036ed5341c36a1e076f9df9f47a3743ef4e6f
imgteam
parents:
diff
changeset
|
18 im = im.squeeze() |
8b74843c136e
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/voronoi_tesselation commit 43f036ed5341c36a1e076f9df9f47a3743ef4e6f
imgteam
parents:
diff
changeset
|
19 assert im.ndim == 2 |
8b74843c136e
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/voronoi_tesselation commit 43f036ed5341c36a1e076f9df9f47a3743ef4e6f
imgteam
parents:
diff
changeset
|
20 |
8b74843c136e
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/voronoi_tesselation commit 43f036ed5341c36a1e076f9df9f47a3743ef4e6f
imgteam
parents:
diff
changeset
|
21 distances = np.full(im.shape, np.inf) |
8b74843c136e
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/voronoi_tesselation commit 43f036ed5341c36a1e076f9df9f47a3743ef4e6f
imgteam
parents:
diff
changeset
|
22 for label in np.unique(im): |
8b74843c136e
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/voronoi_tesselation commit 43f036ed5341c36a1e076f9df9f47a3743ef4e6f
imgteam
parents:
diff
changeset
|
23 if label == 0: |
8b74843c136e
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/voronoi_tesselation commit 43f036ed5341c36a1e076f9df9f47a3743ef4e6f
imgteam
parents:
diff
changeset
|
24 continue |
8b74843c136e
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/voronoi_tesselation commit 43f036ed5341c36a1e076f9df9f47a3743ef4e6f
imgteam
parents:
diff
changeset
|
25 |
8b74843c136e
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/voronoi_tesselation commit 43f036ed5341c36a1e076f9df9f47a3743ef4e6f
imgteam
parents:
diff
changeset
|
26 label_distances = ndi.distance_transform_edt(im != label) |
8b74843c136e
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/voronoi_tesselation commit 43f036ed5341c36a1e076f9df9f47a3743ef4e6f
imgteam
parents:
diff
changeset
|
27 distances = np.min((distances, label_distances), axis=0) |
8b74843c136e
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/voronoi_tesselation commit 43f036ed5341c36a1e076f9df9f47a3743ef4e6f
imgteam
parents:
diff
changeset
|
28 |
8b74843c136e
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/voronoi_tesselation commit 43f036ed5341c36a1e076f9df9f47a3743ef4e6f
imgteam
parents:
diff
changeset
|
29 result = watershed( |
8b74843c136e
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/voronoi_tesselation commit 43f036ed5341c36a1e076f9df9f47a3743ef4e6f
imgteam
parents:
diff
changeset
|
30 image=distances, |
8b74843c136e
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/voronoi_tesselation commit 43f036ed5341c36a1e076f9df9f47a3743ef4e6f
imgteam
parents:
diff
changeset
|
31 markers=im, |
8b74843c136e
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/voronoi_tesselation commit 43f036ed5341c36a1e076f9df9f47a3743ef4e6f
imgteam
parents:
diff
changeset
|
32 ) |
8b74843c136e
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/voronoi_tesselation commit 43f036ed5341c36a1e076f9df9f47a3743ef4e6f
imgteam
parents:
diff
changeset
|
33 |
8b74843c136e
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/voronoi_tesselation commit 43f036ed5341c36a1e076f9df9f47a3743ef4e6f
imgteam
parents:
diff
changeset
|
34 skimage.io.imsave(args.output, result) |