Input: image: HxWx3 numpy flow: HxWx2 torch.Tensor Output: outImg: HxWx3 numpy
(image, flow, padding_mode='zeros')
| 34 | coords = torch.stack(coords[::-1], dim=0).float() |
| 35 | return coords[None].repeat(batch, 1, 1, 1) |
| 36 | def image_flow_warp(image, flow, padding_mode='zeros'): |
| 37 | ''' |
| 38 | Input: |
| 39 | image: HxWx3 numpy |
| 40 | flow: HxWx2 torch.Tensor |
| 41 | Output: |
| 42 | outImg: HxWx3 numpy |
| 43 | ''' |
| 44 | image = torch.from_numpy(image) |
| 45 | if image.ndim == 2: |
| 46 | image = image[None].permute([1,2,0]) |
| 47 | H, W, _ = image.shape |
| 48 | coords = coords_grid(1, H, W).cuda().float().contiguous() |
| 49 | flow = flow[None].repeat(1, 1, 1, 1).permute([0, 3, 1, 2]).float().contiguous() |
| 50 | grid = (flow + coords).permute([0, 2, 3, 1]).contiguous() # (1, H, W, 2) |
| 51 | |
| 52 | grid[:, :, :, 0] = (grid[:, :, :, 0] * 2 - W + 1) / (W - 1) |
| 53 | grid[:, :, :, 1] = (grid[:, :, :, 1] * 2 - H + 1) / (H - 1) |
| 54 | image = image[None].permute([0, 3, 1, 2]).cuda().float() |
| 55 | |
| 56 | outImg = F.grid_sample(image, grid, padding_mode=padding_mode, align_corners=False)[0].cpu().numpy().transpose([1, 2, 0]) |
| 57 | return outImg |
| 58 | |
| 59 | def blend(out, source, scene, blend_type, mask=None, use_colormap=False): |
| 60 | if mask is None: |
no test coverage detected