Mercurial > repos > imgteam > overlay_segmentation_mask
annotate overlay_segmentation_mask.py @ 2:22e573b7dcb1 draft default tip
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/overlay_segmentation_mask/ commit 0500f513ee291ae0f6fad32a0b4fad05cd59cb71"
author | imgteam |
---|---|
date | Sat, 26 Feb 2022 17:14:53 +0000 (2022-02-26) |
parents | 8ad39f493587 |
children |
rev | line source |
---|---|
0
63b2a10b1001
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/overlay_segmentation_mask/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff
changeset
|
1 import argparse |
63b2a10b1001
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/overlay_segmentation_mask/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff
changeset
|
2 |
63b2a10b1001
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/overlay_segmentation_mask/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff
changeset
|
3 import matplotlib |
63b2a10b1001
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/overlay_segmentation_mask/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff
changeset
|
4 import matplotlib.pyplot as plt |
2
22e573b7dcb1
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/overlay_segmentation_mask/ commit 0500f513ee291ae0f6fad32a0b4fad05cd59cb71"
imgteam
parents:
1
diff
changeset
|
5 import skimage.io |
22e573b7dcb1
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/overlay_segmentation_mask/ commit 0500f513ee291ae0f6fad32a0b4fad05cd59cb71"
imgteam
parents:
1
diff
changeset
|
6 import skimage.measure |
0
63b2a10b1001
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/overlay_segmentation_mask/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff
changeset
|
7 |
2
22e573b7dcb1
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/overlay_segmentation_mask/ commit 0500f513ee291ae0f6fad32a0b4fad05cd59cb71"
imgteam
parents:
1
diff
changeset
|
8 matplotlib.use('Agg') |
22e573b7dcb1
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/overlay_segmentation_mask/ commit 0500f513ee291ae0f6fad32a0b4fad05cd59cb71"
imgteam
parents:
1
diff
changeset
|
9 # TODO make importable by python script |
0
63b2a10b1001
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/overlay_segmentation_mask/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff
changeset
|
10 |
63b2a10b1001
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/overlay_segmentation_mask/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff
changeset
|
11 parser = argparse.ArgumentParser() |
63b2a10b1001
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/overlay_segmentation_mask/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff
changeset
|
12 parser.add_argument('input_file', type=argparse.FileType('r'), help='input file') |
63b2a10b1001
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/overlay_segmentation_mask/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff
changeset
|
13 parser.add_argument('mask_file', type=argparse.FileType('r'), help='mask file') |
2
22e573b7dcb1
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/overlay_segmentation_mask/ commit 0500f513ee291ae0f6fad32a0b4fad05cd59cb71"
imgteam
parents:
1
diff
changeset
|
14 parser.add_argument('out_file', type=str, help='out file (PNG)') # file would be created immediately with argparse.FileType('w') s.t. file cannot be renamed on galaxy |
0
63b2a10b1001
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/overlay_segmentation_mask/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff
changeset
|
15 parser.add_argument('--grey', dest='greyscale', action='store_true', help='image is greyscale') |
63b2a10b1001
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/overlay_segmentation_mask/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff
changeset
|
16 parser.add_argument('--label', dest='label', action='store_true', help='plot label') |
63b2a10b1001
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/overlay_segmentation_mask/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff
changeset
|
17 parser.add_argument('--label_color', dest='label_color', default='#FFFF00', help='label color') |
63b2a10b1001
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/overlay_segmentation_mask/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff
changeset
|
18 parser.add_argument('--thickness', dest='thickness', default=0.3, type=float, help='thickness') |
63b2a10b1001
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/overlay_segmentation_mask/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff
changeset
|
19 parser.add_argument('--stroke_color', dest='stroke_color', default='#ff0000', help='stroke color') |
63b2a10b1001
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/overlay_segmentation_mask/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff
changeset
|
20 args = parser.parse_args() |
63b2a10b1001
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/overlay_segmentation_mask/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff
changeset
|
21 img = skimage.io.imread(args.input_file.name) |
63b2a10b1001
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/overlay_segmentation_mask/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff
changeset
|
22 label = skimage.io.imread(args.mask_file.name) |
63b2a10b1001
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/overlay_segmentation_mask/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff
changeset
|
23 |
63b2a10b1001
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/overlay_segmentation_mask/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff
changeset
|
24 fig = plt.figure() |
63b2a10b1001
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/overlay_segmentation_mask/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff
changeset
|
25 ax = fig.add_axes([0, 0, 1, 1]) |
63b2a10b1001
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/overlay_segmentation_mask/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff
changeset
|
26 ax.axis('off') |
63b2a10b1001
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/overlay_segmentation_mask/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff
changeset
|
27 |
63b2a10b1001
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/overlay_segmentation_mask/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff
changeset
|
28 if args.label: |
63b2a10b1001
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/overlay_segmentation_mask/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff
changeset
|
29 for reg in skimage.measure.regionprops(label): |
63b2a10b1001
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/overlay_segmentation_mask/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff
changeset
|
30 ax.text(reg.centroid[1], reg.centroid[0], str(reg.label), color=args.label_color) |
63b2a10b1001
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/overlay_segmentation_mask/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff
changeset
|
31 |
63b2a10b1001
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/overlay_segmentation_mask/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff
changeset
|
32 if args.greyscale: |
63b2a10b1001
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/overlay_segmentation_mask/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff
changeset
|
33 plt.imshow(img, cmap=plt.cm.gray) |
63b2a10b1001
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/overlay_segmentation_mask/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff
changeset
|
34 else: |
63b2a10b1001
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/overlay_segmentation_mask/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff
changeset
|
35 plt.imshow(img) |
63b2a10b1001
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/overlay_segmentation_mask/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff
changeset
|
36 plt.contour(label, linewidths=args.thickness, colors=args.stroke_color) |
63b2a10b1001
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/overlay_segmentation_mask/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff
changeset
|
37 |
1
8ad39f493587
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/overlay_segmentation_mask/ commit b2acc1845a25828181597fe5b6982fe116a7796d
imgteam
parents:
0
diff
changeset
|
38 fig.canvas.print_png(args.out_file) |