MCPcopy Index your code
hub / github.com/tensorpack/tensorpack / visualize

Method visualize

examples/OpticalFlow/helper.py:68–105  ·  view source on GitHub ↗
(self, nnf)

Source from the content-addressed store, hash-verified

66 self.wheel = self.wheel / 255.
67
68 def visualize(self, nnf):
69 assert len(nnf.shape) == 3
70 assert nnf.shape[2] == 2
71
72 RY, YG, GC = 15, 6, 4
73 YG, GC, CB = 6, 4, 11
74 BM, MR = 13, 6
75 NCOLS = RY + YG + GC + CB + BM + MR
76
77 fx = nnf[:, :, 0].astype(np.float32)
78 fy = nnf[:, :, 1].astype(np.float32)
79
80 h, w = fx.shape[:2]
81 fx = fx.reshape([-1])
82 fy = fy.reshape([-1])
83
84 rad = np.sqrt(fx * fx + fy * fy)
85
86 normalizer = max(rad.max(), 1)
87 # This parameter controls how sensitive the visualization is to small displacement
88 # The smaller it is, the more sensitive the visualization is.
89 # We don't let it be smaller than 1 since we don't want to be sensitive to noise.
90
91 a = np.arctan2(-fy, -fx) / np.pi
92 fk = (a + 1.0) / 2.0 * (NCOLS - 1)
93 k0 = fk.astype(np.int32)
94 k1 = (k0 + 1) % NCOLS
95 f = (fk - k0).astype(np.float32)
96
97 color0 = self.wheel[k0, :]
98 color1 = self.wheel[k1, :]
99
100 f = np.stack([f, f, f], axis=-1)
101 color = (1 - f) * color0 + f * color1
102
103 color = 1 - (np.expand_dims(rad, axis=-1) / normalizer) * (1 - color)
104
105 return color.reshape(h, w, 3)[:, :, ::-1]
106
107
108if __name__ == '__main__':

Callers 2

applyFunction · 0.95
helper.pyFile · 0.80

Calls 1

maxMethod · 0.80

Tested by

no test coverage detected