annotate 2d_split_binaryimage_by_watershed.py @ 1:f8f7987586b7 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 05:01:10 -0500
parents 5e21d7342593
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
5e21d7342593 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
5e21d7342593 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
5e21d7342593 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
5e21d7342593 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
5e21d7342593 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
f8f7987586b7 "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
5e21d7342593 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
5e21d7342593 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/2d_split_binaryimage_by_watershed/ commit b2acc1845a25828181597fe5b6982fe116a7796d
imgteam
parents:
diff changeset
8
5e21d7342593 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__":
5e21d7342593 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')
5e21d7342593 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')
5e21d7342593 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)')
5e21d7342593 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')
5e21d7342593 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()
5e21d7342593 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/2d_split_binaryimage_by_watershed/ commit b2acc1845a25828181597fe5b6982fe116a7796d
imgteam
parents:
diff changeset
15
5e21d7342593 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)
5e21d7342593 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)
5e21d7342593 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,
5e21d7342593 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,
5e21d7342593 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,
5e21d7342593 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)
5e21d7342593 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]
5e21d7342593 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)
5e21d7342593 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/2d_split_binaryimage_by_watershed/ commit b2acc1845a25828181597fe5b6982fe116a7796d
imgteam
parents:
diff changeset
24
5e21d7342593 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)
5e21d7342593 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")