INNER CODE UNIT · Python
target_h
Tencent-Hunyuan/HunyuanPortrait · inference.py:58
target_h = y2 - y1
# 1. resize the generated face back to the size of the original crop box
generated_resized = cv2.resize(generated_crop, (target_w, target_h))
# 2. if no mask is provided, create a new one
if mask is None:
mask = create_soft_mask((target_w, target_h))
# 3. get the corresponding region in the original image
background_region = original_img[y1:y2, x1:x2].astype(np.float32) / 255.0
foreground_region = generated_resized.astype(np.float32) / 255.0
# 4. blend: Result = Gen * Mask + BG * (1 - Mask)
blended_region = foreground_region * mask + background_region * (1 - mask)
# 5. paste back to the original image
result_img = original_img.copy()