Mercurial > repos > thomaswollmann > overlay_segmentation_mask
comparison overlay_segmentation_mask.py @ 0:5f83d67e30f1 draft default tip
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/overlay_segmentation_mask/ commit 787ebcc8daa1834214bc92c201c921c704ef2d1f
author | thomaswollmann |
---|---|
date | Mon, 07 Jan 2019 05:38:10 -0500 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:5f83d67e30f1 |
---|---|
1 import argparse | |
2 import sys | |
3 import os | |
4 | |
5 import matplotlib | |
6 matplotlib.use('Agg') | |
7 import matplotlib.pyplot as plt | |
8 | |
9 #TODO make importable by python script | |
10 | |
11 import skimage.io | |
12 import skimage.measure | |
13 | |
14 parser = argparse.ArgumentParser() | |
15 parser.add_argument('input_file', type=argparse.FileType('r'), help='input file') | |
16 parser.add_argument('mask_file', type=argparse.FileType('r'), help='mask file') | |
17 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 | |
18 parser.add_argument('--grey', dest='greyscale', action='store_true', help='image is greyscale') | |
19 parser.add_argument('--label', dest='label', action='store_true', help='plot label') | |
20 parser.add_argument('--label_color', dest='label_color', default='#FFFF00', help='label color') | |
21 parser.add_argument('--thickness', dest='thickness', default=0.3, type=float, help='thickness') | |
22 parser.add_argument('--stroke_color', dest='stroke_color', default='#ff0000', help='stroke color') | |
23 args = parser.parse_args() | |
24 img = skimage.io.imread(args.input_file.name) | |
25 label = skimage.io.imread(args.mask_file.name) | |
26 | |
27 fig = plt.figure() | |
28 ax = fig.add_axes([0, 0, 1, 1]) | |
29 ax.axis('off') | |
30 | |
31 if args.label: | |
32 for reg in skimage.measure.regionprops(label): | |
33 ax.text(reg.centroid[1], reg.centroid[0], str(reg.label), color=args.label_color) | |
34 | |
35 if args.greyscale: | |
36 plt.imshow(img, cmap=plt.cm.gray) | |
37 else: | |
38 plt.imshow(img) | |
39 plt.contour(label, linewidths=args.thickness, colors=args.stroke_color) | |
40 | |
41 fig.canvas.print_png(args.out_file) |