GrowMask can now be used with negative numbers to erode it.

This commit is contained in:
comfyanonymous 2023-09-26 02:45:31 -04:00
parent d2cec6cdbf
commit d76d71de3f
1 changed files with 6 additions and 3 deletions

View File

@ -1,5 +1,5 @@
import numpy as np import numpy as np
from scipy.ndimage import grey_dilation import scipy.ndimage
import torch import torch
import comfy.utils import comfy.utils
@ -311,7 +311,7 @@ class GrowMask:
return { return {
"required": { "required": {
"mask": ("MASK",), "mask": ("MASK",),
"expand": ("INT", {"default": 0, "min": 0, "max": MAX_RESOLUTION, "step": 1}), "expand": ("INT", {"default": 0, "min": -MAX_RESOLUTION, "max": MAX_RESOLUTION, "step": 1}),
"tapered_corners": ("BOOLEAN", {"default": True}), "tapered_corners": ("BOOLEAN", {"default": True}),
}, },
} }
@ -328,8 +328,11 @@ class GrowMask:
[1, 1, 1], [1, 1, 1],
[c, 1, c]]) [c, 1, c]])
output = mask.numpy().copy() output = mask.numpy().copy()
while expand < 0:
output = scipy.ndimage.grey_erosion(output, footprint=kernel)
expand += 1
while expand > 0: while expand > 0:
output = grey_dilation(output, footprint=kernel) output = scipy.ndimage.grey_dilation(output, footprint=kernel)
expand -= 1 expand -= 1
output = torch.from_numpy(output) output = torch.from_numpy(output)
return (output,) return (output,)