-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvis.py
More file actions
193 lines (157 loc) · 7.45 KB
/
vis.py
File metadata and controls
193 lines (157 loc) · 7.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
import os
import pandas as pd
import numpy as np
import copy
from csv import writer
from sklearn.cluster import DBSCAN
import pickle
from bokeh.plotting import figure, output_file, show, output_notebook
import bokeh.io
from bokeh.layouts import gridplot
def pris_show(locs, candidate_locs, lb=None, outputhtml=None, saveoption=False, locs_g=None, inspect_aggregated=False, blur=None, recb=None,blurx=128,blury=128):
locs = np.asarray(locs)
if inspect_aggregated is False:
blur = lb.b.reshape(blurx, blury)
recb = lb.recb.reshape(blurx, blury)
w=blurx
h=blury
pw=400
ph=400
p1 = figure(tooltips=[("x", "$x"), ("y", "$y"), ("value", "@image")],
title='blur')
p1.x_range.range_padding = p1.y_range.range_padding = 0
p1.image(image=[blur], x=0, y=0, dw=w, dh=h, palette="Greys256")
p2 = figure(x_range=p1.x_range, y_range=p1.y_range,
tooltips=[("x", "$x"), ("y", "$y"), ("value", "@image")],
title='reconstructed blur')
p2.x_range.range_padding = p2.y_range.range_padding = 0
p2.image(image=[recb], x=0, y=0, dw=w, dh=h, palette="Greys256")
p3 = figure(x_range=p1.x_range, y_range=p1.y_range,
tooltips=[("x", "$x"), ("y", "$y"), ("value", "@image")],
title='blur + fits (red dots)')
p3.x_range.range_padding = p3.y_range.range_padding = 0
p3.image(image=[blur], x=0, y=0, dw=w, dh=h, palette="Greys256")
p3.scatter(locs[:, 1], locs[:, 0], marker='dot', size=25, color='red')
p4 = figure(x_range=p1.x_range, y_range=p1.y_range,
tooltips=[("x", "$x"), ("y", "$y"), ("value", "@image")],
title='residual')
p4.x_range.range_padding = p4.y_range.range_padding = 0
p4.image(image=[blur - recb], x=0, y=0, dw=w, dh=h, palette="Greys256")
p5 = figure(x_range=p1.x_range, y_range=p1.y_range,
tooltips=[("x", "$x"), ("y", "$y"), ("value", "@image")],
title='blur + ground truth (green crosses)')
p5.x_range.range_padding = p3.y_range.range_padding = 0
p5.image(image=[blur], x=0, y=0, dw=w, dh=h, palette="Greys256")
if locs_g is not None:
p5.scatter(locs_g[:, 1], locs_g[:, 0], marker='cross', size=15, color='green', line_width=2)
p6 = figure(x_range=p1.x_range, y_range=p1.y_range,
tooltips=[("x", "$x"), ("y", "$y"), ("value", "@image")],
title='blur + final fits (red dots) + ground truth (green crosses)')
p6.x_range.range_padding = p4.y_range.range_padding = 0
p6.image(image=[blur], x=0, y=0, dw=w, dh=h, palette="Greys256")
p6.scatter(locs[:, 1], locs[:, 0], marker='dot', size=25, color='red')
if locs_g is not None:
p6.scatter(locs_g[:, 1], locs_g[:, 0], marker='cross', size=15, color='green', line_width=2)
if saveoption:
output_file(outputhtml, title="PRIS0to4 candidate pools")
grid = gridplot([[p1, p2, p4], [p5, p3, p6]], plot_width=pw, plot_height=ph)
show(grid)
return
def bokeh_imshow(im):
p1 = figure(tooltips=[("x", "$x"), ("y", "$y"), ("value", "@image")],
title='blur')
p1.x_range.range_padding = p1.y_range.range_padding = 0
p1.image(image=[im], x=0, y=0, dw=500, dh=500, palette="Greys256")
pw=450
ph=450
grid = gridplot([[p1]], plot_width=500, plot_height=500)
show(grid)
def pris_show_pris0to4(locs, cands0, cands1, cands2, cands3, cands4, lb, outputhtml, saveoption,bdimx=128,bdimy=128):
locs=np.asarray(locs)
blur = lb.b.reshape(bdimx, bdimy)
recb = lb.recb.reshape(bdimx, bdimy)
w=bdimx
h=bdimy
pw=500
ph=500
x0 = cands0
x1 = cands1
x2 = cands2
x3 = cands3
x4 = cands4
x5 = locs
"show the support of pris0 and pris1"
p1 = figure(tooltips=[("x", "$x"), ("y", "$y"), ("value", "@image")],
title='support of pris0 and pris1')
p1.x_range.range_padding = p1.y_range.range_padding = 0
p1.image(image=[blur], x=0, y=0, dw=w, dh=h, palette="Greys256")
try:
p1.scatter(x0[:, 2], x0[:, 1], marker='dot', size=25, color='red')
p1.scatter(x1[:, 2], x1[:, 1], marker='dot', size=25, color='darkorange')
except Warning:
print("no pypris object detected.")
pass
p2 = figure(x_range=p1.x_range, y_range=p1.y_range,
tooltips=[("x", "$x"), ("y", "$y"), ("value", "@image")],
title='support of pris1 and pris2')
p2.x_range.range_padding = p1.y_range.range_padding = 0
p2.image(image=[blur], x=0, y=0, dw=w, dh=h, palette="Greys256")
try:
p2.scatter(x1[:, 2], x1[:, 1], marker='dot', size=25, color='darkorange')
p2.scatter(x2[:, 2], x2[:, 1], marker='dot', size=25, color='green')
except Warning:
print("no pypris object detected.")
pass
p3 = figure(x_range=p2.x_range, y_range=p2.y_range,
tooltips=[("x", "$x"), ("y", "$y"), ("value", "@image")],
title='support of pris2 and pris3')
p3.x_range.range_padding = p2.y_range.range_padding = 0
p3.image(image=[blur], x=0, y=0, dw=w, dh=h, palette="Greys256")
try:
p3.scatter(x2[:, 2], x2[:, 1], marker='dot', size=25, color='green')
p3.scatter(x3[:, 2], x3[:, 1], marker='dot', size=25, color='dodgerblue')
except Warning:
print("no pypris object detected.")
pass
p4 = figure(x_range=p2.x_range, y_range=p2.y_range,
tooltips=[("x", "$x"), ("y", "$y"), ("value", "@image")],
title='support of pris3 and pris4')
p4.x_range.range_padding = p2.y_range.range_padding = 0
p4.image(image=[blur], x=0, y=0, dw=w, dh=h, palette="Greys256")
try:
p4.scatter(x3[:, 2], x3[:, 1], marker='dot', size=25, color='dodgerblue')
p4.scatter(x4[:, 2], x4[:, 1], marker='dot', size=25, color='blue')
except Warning:
print("no pypris object detected.")
pass
p5 = figure(x_range=p2.x_range, y_range=p2.y_range,
tooltips=[("x", "$x"), ("y", "$y"), ("value", "@image")],
title='support of pris4 and final fitting location')
p5.x_range.range_padding = p2.y_range.range_padding = 0
p5.image(image=[blur], x=0, y=0, dw=w, dh=h, palette="Greys256")
try:
p5.scatter(x4[:, 2], x4[:, 1], marker='dot', size=25, color='blue')
p5.scatter(x5[:, 1], x5[:, 0], marker='dot', size=25, color='purple')
except Warning:
print("no pypris object detected.")
pass
p6 = figure(x_range=p2.x_range, y_range=p2.y_range,
tooltips=[("x", "$x"), ("y", "$y"), ("value", "@image")],
title='support of pris1/2/3/4, and final fitting locations.')
p6.x_range.range_padding = p2.y_range.range_padding = 0
p6.image(image=[blur], x=0, y=0, dw=w, dh=h, palette="Greys256")
try:
#p6.scatter(x0[:, 2], x0[:, 1], marker='dot', size=25, color='red')
p6.scatter(x1[:, 2], x1[:, 1], marker='dot', size=25, color='darkorange')
p6.scatter(x2[:, 2], x2[:, 1], marker='dot', size=25, color='green')
p6.scatter(x3[:, 2], x3[:, 1], marker='dot', size=25, color='dodgerblue')
p6.scatter(x4[:, 2], x4[:, 1], marker='dot', size=25, color='blue')
p6.scatter(x5[:, 1], x5[:, 0], marker='dot', size=25, color='purple')
except Warning:
print("no pypris object detected.")
pass
if saveoption:
output_file(outputhtml, title="result (PRIS4)")
grid = gridplot([[p1, p2, p3], [p4, p5, p6]], plot_width=pw, plot_height=ph)
show(grid)
return