Motion: [(M), T, 17, 3]. Normalize to [-1, 1]
(motion, scale_range=[1, 1])
| 5 | import copy |
| 6 | |
| 7 | def crop_scale(motion, scale_range=[1, 1]): |
| 8 | ''' |
| 9 | Motion: [(M), T, 17, 3]. |
| 10 | Normalize to [-1, 1] |
| 11 | ''' |
| 12 | result = copy.deepcopy(motion) |
| 13 | valid_coords = motion[motion[..., 2]!=0][:,:2] |
| 14 | if len(valid_coords) < 4: |
| 15 | return np.zeros(motion.shape) |
| 16 | xmin = min(valid_coords[:,0]) |
| 17 | xmax = max(valid_coords[:,0]) |
| 18 | ymin = min(valid_coords[:,1]) |
| 19 | ymax = max(valid_coords[:,1]) |
| 20 | ratio = np.random.uniform(low=scale_range[0], high=scale_range[1], size=1)[0] |
| 21 | scale = max(xmax-xmin, ymax-ymin) * ratio |
| 22 | if scale==0: |
| 23 | return np.zeros(motion.shape) |
| 24 | xs = (xmin+xmax-scale) / 2 |
| 25 | ys = (ymin+ymax-scale) / 2 |
| 26 | result[...,:2] = (motion[..., :2]- [xs,ys]) / scale |
| 27 | result[...,:2] = (result[..., :2] - 0.5) * 2 |
| 28 | result = np.clip(result, -1, 1) |
| 29 | return result |
| 30 | |
| 31 | def crop_scale_3d(motion, scale_range=[1, 1]): |
| 32 | ''' |
no outgoing calls
no test coverage detected