Mercurial > repos > imgteam > 2d_split_binaryimage_by_watershed
comparison 2d_split_binaryimage_by_watershed.py @ 0:a85f21652677 draft
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/2d_split_binaryimage_by_watershed/ commit b2acc1845a25828181597fe5b6982fe116a7796d
author | imgteam |
---|---|
date | Mon, 22 Jul 2019 04:54:43 -0400 |
parents | |
children | dc373e0d34b7 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:a85f21652677 |
---|---|
1 import argparse | |
2 import sys | |
3 import skimage.io | |
4 from skimage.morphology import watershed | |
5 from skimage.feature import peak_local_max | |
6 from scipy import ndimage as ndi | |
7 import skimage.util | |
8 | |
9 if __name__ == "__main__": | |
10 parser = argparse.ArgumentParser(description='Split binaryimage by watershed') | |
11 parser.add_argument('input_file', type=argparse.FileType('r'), default=sys.stdin, help='input file') | |
12 parser.add_argument('out_file', type=argparse.FileType('w'), default=sys.stdin, help='out file (TIFF)') | |
13 parser.add_argument('min_distance', type=int, default=100, help='Minimum distance to next object') | |
14 args = parser.parse_args() | |
15 | |
16 img_in = skimage.io.imread(args.input_file.name) | |
17 distance = ndi.distance_transform_edt(img_in) | |
18 local_maxi = peak_local_max(distance, | |
19 indices=False, | |
20 min_distance=args.min_distance, | |
21 labels=img_in) | |
22 markers = ndi.label(local_maxi)[0] | |
23 res = watershed(-distance, markers, mask=img_in) | |
24 | |
25 res = skimage.util.img_as_uint(res) | |
26 skimage.io.imsave(args.out_file.name, res, plugin="tifffile") |