-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtimeSurface.py
47 lines (40 loc) · 1.2 KB
/
timeSurface.py
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
import time
import numpy as np
import glob
from tqdm import tqdm
from scipy.io import loadmat
import matplotlib.pyplot as plt
import scipy.ndimage as ndimage
from matplotlib import font_manager as fm, rcParams
# mat = loadmat("digit_one.mat")
event_data = glob.glob("/media/sami/Samsung_T5/MPhil/Dataset/n-mnist/mat/*.mat")
mat = loadmat(event_data[1])
events = mat["TD"]
event_index = events[:,0].shape[0]
events[:,3] = events[:,3] - events[1,3]
xs = 35
ys = 35
tau = 1e4
displayFreq = 1e4
nextTimeSample = events[1,3]+displayFreq
S = np.zeros((xs,ys))
T = np.zeros_like(S)
T = T - np.inf
P = np.zeros_like(T)
for idx in tqdm(range(event_index)):
x = events[idx,0]
y = events[idx,1]
p = events[idx,2]
ts = events[idx,3]
T[x,y] = ts
P[x,y] = p
plt.ion()
if ts > nextTimeSample:
nextTimeSample = max(nextTimeSample + displayFreq,ts)
S = np.multiply(P,np.exp((T-ts)/tau))
new_data = ndimage.rotate(S, -90, reshape=True)
plt.imshow(new_data)
plt.title(r"$\tau$: " + str(tau) + " freq: " + str(displayFreq) + " ts: "+str(ts))
plt.pcolormesh(new_data, cmap='binary')
plt.pause(.1)
plt.draw()