mirror of
https://github.com/comfyanonymous/ComfyUI.git
synced 2025-01-11 10:25:16 +00:00
nodes: add feathering to to ImagePadForOutpaint
This commit is contained in:
parent
3ebf7452c3
commit
4580f3e644
31
nodes.py
31
nodes.py
@ -919,6 +919,7 @@ class ImagePadForOutpaint:
|
|||||||
"top": ("INT", {"default": 0, "min": 0, "max": 4096, "step": 64}),
|
"top": ("INT", {"default": 0, "min": 0, "max": 4096, "step": 64}),
|
||||||
"right": ("INT", {"default": 0, "min": 0, "max": 4096, "step": 64}),
|
"right": ("INT", {"default": 0, "min": 0, "max": 4096, "step": 64}),
|
||||||
"bottom": ("INT", {"default": 0, "min": 0, "max": 4096, "step": 64}),
|
"bottom": ("INT", {"default": 0, "min": 0, "max": 4096, "step": 64}),
|
||||||
|
"feathering": ("INT", {"default": 0, "min": 0, "max": 4096, "step": 1}),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -927,7 +928,7 @@ class ImagePadForOutpaint:
|
|||||||
|
|
||||||
CATEGORY = "image"
|
CATEGORY = "image"
|
||||||
|
|
||||||
def expand_image(self, image, left, top, right, bottom):
|
def expand_image(self, image, left, top, right, bottom, feathering):
|
||||||
d1, d2, d3, d4 = image.size()
|
d1, d2, d3, d4 = image.size()
|
||||||
|
|
||||||
new_image = torch.zeros(
|
new_image = torch.zeros(
|
||||||
@ -940,10 +941,30 @@ class ImagePadForOutpaint:
|
|||||||
(d2 + top + bottom, d3 + left + right),
|
(d2 + top + bottom, d3 + left + right),
|
||||||
dtype=torch.float32,
|
dtype=torch.float32,
|
||||||
)
|
)
|
||||||
mask[top:top + d2, left:left + d3] = torch.zeros(
|
|
||||||
(d2, d3),
|
if feathering > 0 and feathering * 2 < d2 and feathering * 2 < d3:
|
||||||
dtype=torch.float32,
|
# distances to border
|
||||||
)
|
mi, mj = torch.meshgrid(
|
||||||
|
torch.arange(d2, dtype=torch.float32),
|
||||||
|
torch.arange(d3, dtype=torch.float32),
|
||||||
|
indexing='ij',
|
||||||
|
)
|
||||||
|
distances = torch.minimum(
|
||||||
|
torch.minimum(mi, mj),
|
||||||
|
torch.minimum(d2 - 1 - mi, d3 - 1 - mj),
|
||||||
|
)
|
||||||
|
# convert distances to square falloff from 1 to 0
|
||||||
|
t = (feathering - distances) / feathering
|
||||||
|
t.clamp_(min=0)
|
||||||
|
t.square_()
|
||||||
|
|
||||||
|
mask[top:top + d2, left:left + d3] = t
|
||||||
|
else:
|
||||||
|
mask[top:top + d2, left:left + d3] = torch.zeros(
|
||||||
|
(d2, d3),
|
||||||
|
dtype=torch.float32,
|
||||||
|
)
|
||||||
|
|
||||||
return (new_image, mask)
|
return (new_image, mask)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user