mirror of
https://git.datalinker.icu/kijai/ComfyUI-KJNodes.git
synced 2026-05-21 07:07:10 +08:00
Add fill holes option to GrowMaskWithBlur
This commit is contained in:
parent
6f88198cc5
commit
20bc04d287
11
nodes.py
11
nodes.py
@ -9,7 +9,7 @@ import scipy.ndimage
|
|||||||
from scipy.spatial import Voronoi
|
from scipy.spatial import Voronoi
|
||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from PIL import ImageFilter, Image, ImageDraw, ImageFont
|
from PIL import ImageFilter, Image, ImageDraw, ImageFont, ImageOps
|
||||||
from PIL.PngImagePlugin import PngInfo
|
from PIL.PngImagePlugin import PngInfo
|
||||||
import json
|
import json
|
||||||
import re
|
import re
|
||||||
@ -773,6 +773,9 @@ class GrowMaskWithBlur:
|
|||||||
"lerp_alpha": ("FLOAT", {"default": 1.0, "min": 0.0, "max": 1.0, "step": 0.01}),
|
"lerp_alpha": ("FLOAT", {"default": 1.0, "min": 0.0, "max": 1.0, "step": 0.01}),
|
||||||
"decay_factor": ("FLOAT", {"default": 1.0, "min": 0.0, "max": 1.0, "step": 0.01}),
|
"decay_factor": ("FLOAT", {"default": 1.0, "min": 0.0, "max": 1.0, "step": 0.01}),
|
||||||
},
|
},
|
||||||
|
"optional": {
|
||||||
|
"fill_holes": ("BOOLEAN", {"default": False}),
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
CATEGORY = "KJNodes/masking"
|
CATEGORY = "KJNodes/masking"
|
||||||
@ -781,7 +784,7 @@ class GrowMaskWithBlur:
|
|||||||
RETURN_NAMES = ("mask", "mask_inverted",)
|
RETURN_NAMES = ("mask", "mask_inverted",)
|
||||||
FUNCTION = "expand_mask"
|
FUNCTION = "expand_mask"
|
||||||
|
|
||||||
def expand_mask(self, mask, expand, tapered_corners, flip_input, blur_radius, incremental_expandrate, lerp_alpha, decay_factor):
|
def expand_mask(self, mask, expand, tapered_corners, flip_input, blur_radius, incremental_expandrate, lerp_alpha, decay_factor, fill_holes=False):
|
||||||
alpha = lerp_alpha
|
alpha = lerp_alpha
|
||||||
decay = decay_factor
|
decay = decay_factor
|
||||||
if flip_input:
|
if flip_input:
|
||||||
@ -805,6 +808,10 @@ class GrowMaskWithBlur:
|
|||||||
current_expand -= abs(incremental_expandrate)
|
current_expand -= abs(incremental_expandrate)
|
||||||
else:
|
else:
|
||||||
current_expand += abs(incremental_expandrate)
|
current_expand += abs(incremental_expandrate)
|
||||||
|
if fill_holes:
|
||||||
|
binary_mask = output > 0
|
||||||
|
output = scipy.ndimage.binary_fill_holes(binary_mask)
|
||||||
|
output = output.astype(np.uint8) * 255
|
||||||
output = torch.from_numpy(output)
|
output = torch.from_numpy(output)
|
||||||
if alpha < 1.0 and previous_output is not None:
|
if alpha < 1.0 and previous_output is not None:
|
||||||
# Interpolate between the previous and current frame
|
# Interpolate between the previous and current frame
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user