annotate detection_viz.py @ 4:99433164b593 draft default tip

planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/detection_viz/ commit 2286a6c9da88596349ed9d967c51541409c0a7bf
author imgteam
date Mon, 13 Nov 2023 22:11:04 +0000
parents cb2d9de888a1
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
3f738d5d91bf planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/detection_viz/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
1 import argparse
3f738d5d91bf planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/detection_viz/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
2 import csv
4
99433164b593 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/detection_viz/ commit 2286a6c9da88596349ed9d967c51541409c0a7bf
imgteam
parents: 3
diff changeset
3
0
3f738d5d91bf planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/detection_viz/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
4 import matplotlib
4
99433164b593 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/detection_viz/ commit 2286a6c9da88596349ed9d967c51541409c0a7bf
imgteam
parents: 3
diff changeset
5 import matplotlib.pyplot as plt
99433164b593 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/detection_viz/ commit 2286a6c9da88596349ed9d967c51541409c0a7bf
imgteam
parents: 3
diff changeset
6 import skimage.io
99433164b593 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/detection_viz/ commit 2286a6c9da88596349ed9d967c51541409c0a7bf
imgteam
parents: 3
diff changeset
7
99433164b593 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/detection_viz/ commit 2286a6c9da88596349ed9d967c51541409c0a7bf
imgteam
parents: 3
diff changeset
8
0
3f738d5d91bf planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/detection_viz/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
9 matplotlib.use('Agg')
3f738d5d91bf planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/detection_viz/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
10
3f738d5d91bf planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/detection_viz/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
11
3f738d5d91bf planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/detection_viz/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
12 def plot_circles(file_name, ax, color, stroke_size, radius):
3f738d5d91bf planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/detection_viz/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
13 resfile = open(file_name, 'rb')
3f738d5d91bf planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/detection_viz/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
14 rd = csv.reader(resfile, delimiter=',')
3f738d5d91bf planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/detection_viz/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
15 for row in rd:
3f738d5d91bf planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/detection_viz/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
16 circ = plt.Circle((int(row[1]), int(row[0])), lw=stroke_size, radius=radius, color=color, fill=False)
3f738d5d91bf planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/detection_viz/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
17 ax.add_patch(circ)
3f738d5d91bf planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/detection_viz/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
18 resfile.close()
3f738d5d91bf planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/detection_viz/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
19
4
99433164b593 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/detection_viz/ commit 2286a6c9da88596349ed9d967c51541409c0a7bf
imgteam
parents: 3
diff changeset
20
0
3f738d5d91bf planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/detection_viz/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
21 def detection_viz(input_file, output_file, tp=None, fn=None, fp=None, stroke_size=3, circle_radius=50):
3f738d5d91bf planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/detection_viz/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
22 img = skimage.io.imread(input_file)
3f738d5d91bf planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/detection_viz/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
23
3f738d5d91bf planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/detection_viz/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
24 fig = plt.figure(figsize=(40, 40))
4
99433164b593 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/detection_viz/ commit 2286a6c9da88596349ed9d967c51541409c0a7bf
imgteam
parents: 3
diff changeset
25 ax = fig.add_axes([0, 0, 1, 1])
0
3f738d5d91bf planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/detection_viz/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
26 ax.axis('off')
3f738d5d91bf planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/detection_viz/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
27
3f738d5d91bf planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/detection_viz/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
28 plt.imshow(img)
3f738d5d91bf planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/detection_viz/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
29 if tp is not None:
3f738d5d91bf planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/detection_viz/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
30 plot_circles(tp, ax, '#00FF00', stroke_size, circle_radius)
3f738d5d91bf planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/detection_viz/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
31 if fn is not None:
3f738d5d91bf planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/detection_viz/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
32 plot_circles(fn, ax, 'red', stroke_size, circle_radius)
3f738d5d91bf planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/detection_viz/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
33 if fp is not None:
3f738d5d91bf planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/detection_viz/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
34 plot_circles(fp, ax, 'darkorange', stroke_size, circle_radius)
3f738d5d91bf planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/detection_viz/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
35
3f738d5d91bf planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/detection_viz/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
36 fig.canvas.print_png(output_file, dpi=1800)
3f738d5d91bf planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/detection_viz/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
37
4
99433164b593 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/detection_viz/ commit 2286a6c9da88596349ed9d967c51541409c0a7bf
imgteam
parents: 3
diff changeset
38
0
3f738d5d91bf planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/detection_viz/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
39 if __name__ == "__main__":
3f738d5d91bf planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/detection_viz/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
40 parser = argparse.ArgumentParser()
3f738d5d91bf planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/detection_viz/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
41 parser.add_argument('input_file', type=argparse.FileType('r'), help='original file')
3f738d5d91bf planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/detection_viz/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
42 # output file should not be of type argparse.FileType('w') sine it is created immediately in this case which leads to an error in renaming
4
99433164b593 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/detection_viz/ commit 2286a6c9da88596349ed9d967c51541409c0a7bf
imgteam
parents: 3
diff changeset
43 parser.add_argument('out_file_str', type=str, help='string of output file name')
0
3f738d5d91bf planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/detection_viz/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
44 parser.add_argument('--tp', dest='input_tp_file', type=argparse.FileType('r'), help='input TP file')
3f738d5d91bf planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/detection_viz/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
45 parser.add_argument('--fn', dest='input_fn_file', type=argparse.FileType('r'), help='input FN file')
3f738d5d91bf planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/detection_viz/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
46 parser.add_argument('--fp', dest='input_fp_file', type=argparse.FileType('r'), help='input FP file')
3f738d5d91bf planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/detection_viz/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
47 parser.add_argument('--stroke_size', dest='thickness', default=3, type=float, help='stroke thickness')
3f738d5d91bf planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/detection_viz/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
48 parser.add_argument('--circle_radius', dest='circle_radius', type=float, default=50, help='circle radius')
3f738d5d91bf planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/detection_viz/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
49 args = parser.parse_args()
3f738d5d91bf planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/detection_viz/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
50
4
99433164b593 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/detection_viz/ commit 2286a6c9da88596349ed9d967c51541409c0a7bf
imgteam
parents: 3
diff changeset
51 tp = None
0
3f738d5d91bf planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/detection_viz/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
52 if args.input_tp_file:
4
99433164b593 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/detection_viz/ commit 2286a6c9da88596349ed9d967c51541409c0a7bf
imgteam
parents: 3
diff changeset
53 tp = args.input_tp_file.name
99433164b593 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/detection_viz/ commit 2286a6c9da88596349ed9d967c51541409c0a7bf
imgteam
parents: 3
diff changeset
54 fn = None
0
3f738d5d91bf planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/detection_viz/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
55 if args.input_fn_file:
4
99433164b593 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/detection_viz/ commit 2286a6c9da88596349ed9d967c51541409c0a7bf
imgteam
parents: 3
diff changeset
56 fn = args.input_fn_file.name
99433164b593 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/detection_viz/ commit 2286a6c9da88596349ed9d967c51541409c0a7bf
imgteam
parents: 3
diff changeset
57 fp = None
0
3f738d5d91bf planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/detection_viz/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
58 if args.input_fp_file:
4
99433164b593 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/detection_viz/ commit 2286a6c9da88596349ed9d967c51541409c0a7bf
imgteam
parents: 3
diff changeset
59 fp = args.input_fp_file.name
0
3f738d5d91bf planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/detection_viz/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
60
3f738d5d91bf planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/detection_viz/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
61 detection_viz(args.input_file.name, args.out_file_str, tp=tp, fn=fn, fp=fp, stroke_size=args.thickness, circle_radius=args.circle_radius)