(scene_images, marker, flow_estimator, estimate_uncertainty, source=None, blend_type='D', use_colormap=True)
| 71 | return result, mask |
| 72 | |
| 73 | def blend_pdc(scene_images, marker, flow_estimator, estimate_uncertainty, source=None, blend_type='D', use_colormap=True): |
| 74 | print('blend with pdc') |
| 75 | blends = [] |
| 76 | masks = [] |
| 77 | blends_colormap = [] |
| 78 | for id, scene in tqdm(enumerate(scene_images), total=len(scene_images)): |
| 79 | marker = cv2.resize(marker, (scene.shape[1], scene.shape[0])) |
| 80 | Is_original = np.ascontiguousarray(marker) |
| 81 | It_original = np.ascontiguousarray(scene) |
| 82 | Is_tensor = torch.from_numpy(Is_original).permute(2,0,1).unsqueeze(0) |
| 83 | It_tensor = torch.from_numpy(It_original).permute(2,0,1).unsqueeze(0) |
| 84 | with torch.no_grad(): |
| 85 | flow, uncertainty_est = flow_estimator.estimate_flow_and_confidence_map(Is_tensor, It_tensor) |
| 86 | |
| 87 | out = image_flow_warp(marker, flow[0].permute([1,2,0])) |
| 88 | mask_origin = np.ones(shape=(marker.shape[0], marker.shape[1], 1)).astype(np.float64) |
| 89 | mask_origin = image_flow_warp(mask_origin, flow[0].permute([1,2,0]),padding_mode='zeros') |
| 90 | mask = (1 - mask_origin) |
| 91 | |
| 92 | if blend_type == 'mix': |
| 93 | scene_id = 3 * int(id / 3) |
| 94 | source = scene_images[scene_id] |
| 95 | blend_i, mask_i = blend(out, source, scene, blend_type, mask=mask) |
| 96 | blends.append(blend_i) |
| 97 | masks.append(mask_i) |
| 98 | |
| 99 | if use_colormap: |
| 100 | colormap = get_colormap(flow, scene.shape[0], scene.shape[1]) |
| 101 | out_colormap = image_flow_warp(colormap, flow[0].permute([1,2,0])) |
| 102 | out_colormap = ((out_colormap + 256) / 2) |
| 103 | mask_colormap = np.ones_like(colormap).astype(np.float32) / 2 |
| 104 | mask_colormap = image_flow_warp(mask_colormap, flow[0].permute([1,2,0])) |
| 105 | mask_colormap = (1 - mask_colormap) |
| 106 | if blend_type == 'L' or blend_type == 'mix': |
| 107 | scene = source |
| 108 | blend_colormap = (out_colormap * (1 - mask_colormap) + scene * mask_colormap).astype(np.uint8) |
| 109 | blends_colormap.append(blend_colormap) |
| 110 | return blends, masks, blends_colormap |
| 111 | |
| 112 | def blend_life(scene_images, marker, estimator, source=None, blend_type='D', warp='grid_sample', use_colormap=True): |
| 113 | print('blend with our model') |
no test coverage detected