| 189 | |
| 190 | |
| 191 | def build_alpha_pyramid(color, alpha, dk=1.2): |
| 192 | # Written by lvmin at Stanford |
| 193 | # Massive iterative Gaussian filters are mathematically consistent to pyramid. |
| 194 | |
| 195 | pyramid = [] |
| 196 | current_premultiplied_color = color * alpha |
| 197 | current_alpha = alpha |
| 198 | |
| 199 | while True: |
| 200 | pyramid.append((current_premultiplied_color, current_alpha)) |
| 201 | |
| 202 | H, W, C = current_alpha.shape |
| 203 | if min(H, W) == 1: |
| 204 | break |
| 205 | |
| 206 | current_premultiplied_color = cv2.resize(current_premultiplied_color, (int(W / dk), int(H / dk)), interpolation=cv2.INTER_AREA) |
| 207 | current_alpha = cv2.resize(current_alpha, (int(W / dk), int(H / dk)), interpolation=cv2.INTER_AREA)[:, :, None] |
| 208 | return pyramid[::-1] |
| 209 | |
| 210 | |
| 211 | def pad_rgb(np_rgba_hwc_uint8): |