1 """Implements various visualization utils."""
6 def viz_flow(u,v,logscale=True,scaledown=6,output=False):
7 """Flow visualization implentations.
8 The code obtained from PCA flow github repo.
9 https://github.com/jswulff/pcaflow/blob/master/pcaflow/utils/viz_flow.py
11 topleft is zero, u is horiz, v is vertical
12 red is 3 o'clock, yellow is 6, light blue is 9, blue/purple is 12
14 colorwheel = makecolorwheel()
15 ncols = colorwheel.shape[0]
17 radius = np.sqrt(u**2 + v**2)
19 print("Maximum flow magnitude: %04f" % np.max(radius))
21 radius = np.log(radius + 1)
23 print("Maximum flow magnitude (after log): %0.4f" % np.max(radius))
24 radius = radius / scaledown
26 print("Maximum flow magnitude (after scaledown): %0.4f" % np.max(radius))
27 rot = np.arctan2(-v, -u) / np.pi
29 fk = (rot+1)/2 * (ncols-1) # -1~1 maped to 0~ncols
30 k0 = fk.astype(np.uint8) # 0, 1, 2, ..., ncols
37 ncolors = colorwheel.shape[1]
38 img = np.zeros(u.shape+(ncolors,))
39 for i in range(ncolors):
43 col = (1-f)*col0 + f*col1
46 # increase saturation with radius
47 col[idx] = 1 - radius[idx]*(1-col[idx])
50 img[:,:,i] = np.floor(255*col).astype(np.uint8)
51 return img.astype(np.uint8)
54 """Flow visualization implentations.
55 The code obtained from PCA flow github repo.
56 https://github.com/jswulff/pcaflow/blob/master/pcaflow/utils/viz_flow.py
58 # Create a colorwheel for visualization
66 ncols = RY + YG + GC + CB + BM + MR
68 colorwheel = np.zeros((ncols,3))
72 colorwheel[0:RY,0] = 1
73 colorwheel[0:RY,1] = np.arange(0,1,1./RY)
77 colorwheel[col:col+YG,0] = np.arange(1,0,-1./YG)
78 colorwheel[col:col+YG,1] = 1
82 colorwheel[col:col+GC,1] = 1
83 colorwheel[col:col+GC,2] = np.arange(0,1,1./GC)
87 colorwheel[col:col+CB,1] = np.arange(1,0,-1./CB)
88 colorwheel[col:col+CB,2] = 1
92 colorwheel[col:col+BM,2] = 1
93 colorwheel[col:col+BM,0] = np.arange(0,1,1./BM)
97 colorwheel[col:col+MR,2] = np.arange(1,0,-1./MR)
98 colorwheel[col:col+MR,0] = 1