def images_loop(self, decays, display_mode):
import pylab
fig = pylab.figure()
num_images = len(decays)
pylab.ion()
imgs = []
for i in range(len(decays)):
fig.add_subplot(1, num_images, i+1)
imgs.append( pylab.imshow(self.images[i], vmax=1, vmin=-1,
interpolation='none', cmap='binary') )
pylab.xlim(0, 127)
pylab.ylim(127, 0)
regions = {}
if self.count_spike_regions is not None:
for k, v in self.count_spike_regions.items():
minx, miny, maxx, maxy = v
rect = pylab.Rectangle((minx - 0.5, miny - 0.5),
maxx - minx,
maxy - miny,
facecolor='yellow', alpha=0.2)
pylab.gca().add_patch(rect)
regions[k] = rect
if self.track_periods is not None:
colors = ([(0,0,1), (0,1,0), (1,0,0), (1,1,0), (1,0,1)] * 10)[:len(self.p_y)]
scatter = pylab.scatter(self.p_x, self.p_y, s=50, c=colors)
else:
scatter = None
while True:
for i,d in enumerate(decays):
imgs[i].set_data(self.images[i])
for k, rect in regions.items():
alpha = self.get_spike_rate(k) * 0.5
alpha = min(alpha, 0.5)
rect.set_alpha(0.05 + alpha)
if scatter is not None:
scatter.set_offsets(np.array([self.p_x, self.p_y]).T)
c = [(r,g,b,min(self.track_certainty[i],1)) for i,(r,g,b) in enumerate(colors)]
scatter.set_color(c)
if display_mode == 'quick':
# this is much faster, but doesn't work on all systems
fig.canvas.draw()
fig.canvas.flush_events()
else:
# this works on all systems, but is kinda slow
pylab.pause(0.001)
for i,d in enumerate(decays):
self.images[i] *= d
评论列表
文章目录