Merge pull request #119 from fiskbil/blur-result-mask

Add gaussian blur to mask before blending original image with result
This commit is contained in:
Qing 2022-11-12 22:18:55 +08:00 committed by GitHub
commit a4d62f8186
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -3,6 +3,7 @@ from typing import Optional
import cv2 import cv2
import torch import torch
import numpy as np
from loguru import logger from loguru import logger
from lama_cleaner.helper import boxes_from_mask, resize_max_size, pad_img_to_modulo from lama_cleaner.helper import boxes_from_mask, resize_max_size, pad_img_to_modulo
@ -55,8 +56,12 @@ class InpaintModel:
result = self.forward(pad_image, pad_mask, config) result = self.forward(pad_image, pad_mask, config)
result = result[0:origin_height, 0:origin_width, :] result = result[0:origin_height, 0:origin_width, :]
original_pixel_indices = mask < 127 if config.sd_mask_blur != 0:
result[original_pixel_indices] = image[:, :, ::-1][original_pixel_indices] k = 2 * config.sd_mask_blur + 1
mask = cv2.GaussianBlur(mask, (k, k), 0)
mask = mask[:, :, np.newaxis]
result = result * (mask / 255) + image[:, :, ::-1] * (1 - (mask / 255))
return result return result
@torch.no_grad() @torch.no_grad()