r"""Convert flow tensor to color image. Args: tensor (tensor) of If tensor then (NxCxHxW) or (NxTxCxHxW) or (CxHxW). imtype (np.dtype): Type of output image. Returns: (numpy.ndarray or normalized torch image).
(tensor)
| 5 | |
| 6 | |
| 7 | def tensor2flow(tensor): |
| 8 | r"""Convert flow tensor to color image. |
| 9 | |
| 10 | Args: |
| 11 | tensor (tensor) of |
| 12 | If tensor then (NxCxHxW) or (NxTxCxHxW) or (CxHxW). |
| 13 | imtype (np.dtype): Type of output image. |
| 14 | |
| 15 | Returns: |
| 16 | (numpy.ndarray or normalized torch image). |
| 17 | """ |
| 18 | if tensor is None: |
| 19 | return None |
| 20 | if isinstance(tensor, list): |
| 21 | return [tensor2flow(t) for t in tensor] |
| 22 | if tensor.dim() == 5 or tensor.dim() == 4: |
| 23 | return [tensor2flow(tensor[b]) for b in range(tensor.size(0))] |
| 24 | |
| 25 | tensor = tensor.detach().cpu().float().numpy() |
| 26 | tensor = np.transpose(tensor, (1, 2, 0)) |
| 27 | return flow2img(tensor) |
| 28 | |
| 29 | # code from nvidia imaginaire |
| 30 | # |
| 31 | # hsv = np.zeros((tensor.shape[0], tensor.shape[1], 3), dtype=imtype) |
| 32 | # hsv[:, :, 0] = 255 |
| 33 | # hsv[:, :, 1] = 255 |
| 34 | # mag, ang = cv2.cartToPolar(tensor[..., 0], tensor[..., 1]) |
| 35 | # hsv[..., 0] = ang * 180 / np.pi / 2 |
| 36 | # hsv[..., 2] = cv2.normalize(mag, None, 0, 255, cv2.NORM_MINMAX) |
| 37 | # rgb = cv2.cvtColor(hsv, cv2.COLOR_HSV2RGB) |
| 38 | # return rgb |
| 39 | |
| 40 | |
| 41 | # copied from |
nothing calls this directly
no test coverage detected