INNER CODE UNIT · Python

create_soft_mask

Tencent-Hunyuan/HunyuanPortrait · gradio_app.py:130

def create_soft_mask(size, border_ratio=0.1):
    """create a soft mask with edge blurring for smooth blending."""
    w, h = size
    mask = np.ones((h, w), dtype=np.float32)
    border_w = int(w * border_ratio)
    border_h = int(h * border_ratio)
    
    if border_w > 0:
        mask[:, :border_w] = np.linspace(0, 1, border_w)[None, :]
        mask[:, -border_w:] = np.linspace(1, 0, border_w)[None, :]
    if border_h > 0:
        mask[:border_h, :] *= np.linspace(0, 1, border_h)[:, None]
        mask[-border_h:, :] *= np.linspace(1, 0, border_h)[:, None]
        
    return mask[..., None]

def paste_back_frame(original_img, generated_crop, crop_bbox, mask=None):
    """paste the generated cropped frame back to the original image"""

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…