def make_td_probability_image(td, skip_steps=0, is_normalize = False):
"""Generate image from the Temporal Difference (td) events with each pixel value indicating probability of a spike within a 1 millisecond time step. 0 = 0%. 255 = 100%
td is read from a binary file (refer to eventvision.Readxxx functions)
td: eventvision.Events
skip_steps: number of time steps to skip (to allow tracker to init to a more correct position)
is_normalize: True to make the images more obvious (by scaling max probability to pixel value 255)
"""
assert isinstance(td, ev.Events)
#with timer.Timer() as my_timer:
event_offset = 0
combined_image = np.zeros((td.height, td.width), np.float32)
offset_ts = td.data[0].ts + (skip_steps * 1000)
num_time_steps = math.floor((td.data[-1].ts - offset_ts) / 1000)
current_frame = np.zeros((td.height, td.width), np.uint8)
for start_ts in range(int(offset_ts), td.data[-1].ts, 1000):
end_ts = start_ts + 1000
frame_data = td.data[(td.data.ts >= start_ts) & (td.data.ts < end_ts)]
current_frame.fill(0)
current_frame[frame_data.y, frame_data.x] = 1
combined_image = combined_image + current_frame
#print 'Making image out of bin file took %s seconds' % my_timer.secs
if (is_normalize):
combined_image = (combined_image / np.max(combined_image))
else:
combined_image = (combined_image / num_time_steps)
return combined_image
评论列表
文章目录