mirror of
https://github.com/comfyanonymous/ComfyUI.git
synced 2025-04-20 11:23:29 +00:00
Merge branch 'feat-add-image-pad-for-outpaint' of https://github.com/guoyk93/ComfyUI
This commit is contained in:
commit
d741e7aac8
64
nodes.py
64
nodes.py
@ -908,6 +908,69 @@ class ImageInvert:
|
|||||||
return (s,)
|
return (s,)
|
||||||
|
|
||||||
|
|
||||||
|
class ImagePadForOutpaint:
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def INPUT_TYPES(s):
|
||||||
|
return {
|
||||||
|
"required": {
|
||||||
|
"image": ("IMAGE",),
|
||||||
|
"left": ("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}),
|
||||||
|
"bottom": ("INT", {"default": 0, "min": 0, "max": 4096, "step": 64}),
|
||||||
|
"feathering": ("INT", {"default": 0, "min": 0, "max": 4096, "step": 1}),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
RETURN_TYPES = ("IMAGE", "MASK")
|
||||||
|
FUNCTION = "expand_image"
|
||||||
|
|
||||||
|
CATEGORY = "image"
|
||||||
|
|
||||||
|
def expand_image(self, image, left, top, right, bottom, feathering):
|
||||||
|
d1, d2, d3, d4 = image.size()
|
||||||
|
|
||||||
|
new_image = torch.zeros(
|
||||||
|
(d1, d2 + top + bottom, d3 + left + right, d4),
|
||||||
|
dtype=torch.float32,
|
||||||
|
)
|
||||||
|
new_image[:, top:top + d2, left:left + d3, :] = image
|
||||||
|
|
||||||
|
mask = torch.ones(
|
||||||
|
(d2 + top + bottom, d3 + left + right),
|
||||||
|
dtype=torch.float32,
|
||||||
|
)
|
||||||
|
|
||||||
|
t = torch.zeros(
|
||||||
|
(d2, d3),
|
||||||
|
dtype=torch.float32
|
||||||
|
)
|
||||||
|
|
||||||
|
if feathering > 0 and feathering * 2 < d2 and feathering * 2 < d3:
|
||||||
|
|
||||||
|
for i in range(d2):
|
||||||
|
for j in range(d3):
|
||||||
|
dt = i if top != 0 else d2
|
||||||
|
db = d2 - i if bottom != 0 else d2
|
||||||
|
|
||||||
|
dl = j if left != 0 else d3
|
||||||
|
dr = d3 - j if right != 0 else d3
|
||||||
|
|
||||||
|
d = min(dt, db, dl, dr)
|
||||||
|
|
||||||
|
if d >= feathering:
|
||||||
|
continue
|
||||||
|
|
||||||
|
v = (feathering - d) / feathering
|
||||||
|
|
||||||
|
t[i, j] = v * v
|
||||||
|
|
||||||
|
mask[top:top + d2, left:left + d3] = t
|
||||||
|
|
||||||
|
return (new_image, mask)
|
||||||
|
|
||||||
|
|
||||||
NODE_CLASS_MAPPINGS = {
|
NODE_CLASS_MAPPINGS = {
|
||||||
"KSampler": KSampler,
|
"KSampler": KSampler,
|
||||||
"CheckpointLoader": CheckpointLoader,
|
"CheckpointLoader": CheckpointLoader,
|
||||||
@ -926,6 +989,7 @@ NODE_CLASS_MAPPINGS = {
|
|||||||
"LoadImageMask": LoadImageMask,
|
"LoadImageMask": LoadImageMask,
|
||||||
"ImageScale": ImageScale,
|
"ImageScale": ImageScale,
|
||||||
"ImageInvert": ImageInvert,
|
"ImageInvert": ImageInvert,
|
||||||
|
"ImagePadForOutpaint": ImagePadForOutpaint,
|
||||||
"ConditioningCombine": ConditioningCombine,
|
"ConditioningCombine": ConditioningCombine,
|
||||||
"ConditioningSetArea": ConditioningSetArea,
|
"ConditioningSetArea": ConditioningSetArea,
|
||||||
"KSamplerAdvanced": KSamplerAdvanced,
|
"KSamplerAdvanced": KSamplerAdvanced,
|
||||||
|
Loading…
Reference in New Issue
Block a user