nodes: add ImagePadForOutpaint

This commit is contained in:
Guo Y.K 2023-03-23 23:33:35 +08:00
parent dd095efc2c
commit 3ebf7452c3
No known key found for this signature in database
GPG Key ID: 315A5D46A979A359
1 changed files with 40 additions and 0 deletions

View File

@ -908,6 +908,45 @@ class ImageInvert:
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}),
}
}
RETURN_TYPES = ("IMAGE", "MASK")
FUNCTION = "expand_image"
CATEGORY = "image"
def expand_image(self, image, left, top, right, bottom):
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,
)
mask[top:top + d2, left:left + d3] = torch.zeros(
(d2, d3),
dtype=torch.float32,
)
return (new_image, mask)
NODE_CLASS_MAPPINGS = {
"KSampler": KSampler,
"CheckpointLoader": CheckpointLoader,
@ -926,6 +965,7 @@ NODE_CLASS_MAPPINGS = {
"LoadImageMask": LoadImageMask,
"ImageScale": ImageScale,
"ImageInvert": ImageInvert,
"ImagePadForOutpaint": ImagePadForOutpaint,
"ConditioningCombine": ConditioningCombine,
"ConditioningSetArea": ConditioningSetArea,
"KSamplerAdvanced": KSamplerAdvanced,