From c4957772fb1b9642bc7fbbddeaa1d3ce31d84f32 Mon Sep 17 00:00:00 2001 From: Luis Quesada Date: Mon, 13 May 2024 09:10:41 +0200 Subject: [PATCH] Fix fill_holes breaking mask at the borders --- inpaint_cropandstitch.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/inpaint_cropandstitch.py b/inpaint_cropandstitch.py index f4758ef..691bad4 100644 --- a/inpaint_cropandstitch.py +++ b/inpaint_cropandstitch.py @@ -1,5 +1,4 @@ import comfy.utils -import math import nodes import numpy as np import torch @@ -93,7 +92,7 @@ class InpaintCrop: mask_np = m.numpy() binary_mask = mask_np > 0 struct = np.ones((5, 5)) - closed_mask = binary_closing(binary_mask, structure=struct) + closed_mask = binary_closing(binary_mask, structure=struct, border_value=1) filled_mask = binary_fill_holes(closed_mask) output = filled_mask.astype(np.float32) * 255 output = torch.from_numpy(output) @@ -115,8 +114,8 @@ class InpaintCrop: if internal_upscale_factor < 0.999 or internal_upscale_factor > 1.001: samples = image samples = samples.movedim(-1, 1) - width = math.ceil(samples.shape[3] * internal_upscale_factor) - height = math.ceil(samples.shape[2] * internal_upscale_factor) + width = round(samples.shape[3] * internal_upscale_factor) + height = round(samples.shape[2] * internal_upscale_factor) samples = comfy.utils.bislerp(samples, width, height) effective_upscale_factor_x = float(width)/float(original_width) effective_upscale_factor_y = float(height)/float(original_height)