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