(np_rgba_hwc_uint8)
| 203 | |
| 204 | |
| 205 | def pad_rgb(np_rgba_hwc_uint8): |
| 206 | np_rgba_hwc = np_rgba_hwc_uint8.astype(np.float32) / 255.0 |
| 207 | pyramid = build_alpha_pyramid(color=np_rgba_hwc[..., :3], alpha=np_rgba_hwc[..., 3:]) |
| 208 | |
| 209 | top_c, top_a = pyramid[0] |
| 210 | fg = np.sum(top_c, axis=(0, 1), keepdims=True) / np.sum(top_a, axis=(0, 1), keepdims=True).clip(1e-8, 1e32) |
| 211 | |
| 212 | for layer_c, layer_a in pyramid: |
| 213 | layer_h, layer_w, _ = layer_c.shape |
| 214 | fg = cv2.resize(fg, (layer_w, layer_h), interpolation=cv2.INTER_LINEAR) |
| 215 | fg = layer_c + fg * (1.0 - layer_a) |
| 216 | |
| 217 | return fg |
| 218 | |
| 219 | |
| 220 | class TransparentVAEDecoder: |
no test coverage detected