mirror of
https://github.com/comfyanonymous/ComfyUI.git
synced 2026-05-13 10:42:59 +08:00
Add translate option to composite
This commit is contained in:
parent
e570d027a3
commit
71f939c3ed
@ -1,7 +1,7 @@
|
|||||||
import numpy as np
|
import numpy as np
|
||||||
import torch
|
import torch
|
||||||
import torch.nn.functional as F
|
import torch.nn.functional as F
|
||||||
from PIL import Image, ImageColor
|
from PIL import Image, ImageColor, ImageOps
|
||||||
import re
|
import re
|
||||||
|
|
||||||
import comfy.utils
|
import comfy.utils
|
||||||
@ -429,6 +429,8 @@ class Composite:
|
|||||||
"image_a": ("IMAGE",),
|
"image_a": ("IMAGE",),
|
||||||
"image_b": ("IMAGE",),
|
"image_b": ("IMAGE",),
|
||||||
"mask": ("MASK",),
|
"mask": ("MASK",),
|
||||||
|
"x": ("INT", {"default": 0, "min": -MAX_RESOLUTION, "max": MAX_RESOLUTION}),
|
||||||
|
"y": ("INT", {"default": 0, "min": -MAX_RESOLUTION, "max": MAX_RESOLUTION}),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -437,7 +439,7 @@ class Composite:
|
|||||||
|
|
||||||
CATEGORY = "image/postprocessing"
|
CATEGORY = "image/postprocessing"
|
||||||
|
|
||||||
def composite(self, image_a: torch.Tensor, image_b: torch.Tensor, mask: torch.Tensor):
|
def composite(self, image_a: torch.Tensor, image_b: torch.Tensor, mask: torch.Tensor, x: int, y: int):
|
||||||
batch_size, height, width, _ = image_a.shape
|
batch_size, height, width, _ = image_a.shape
|
||||||
result = torch.zeros_like(image_a)
|
result = torch.zeros_like(image_a)
|
||||||
|
|
||||||
@ -449,9 +451,9 @@ class Composite:
|
|||||||
pil_image_b = Image.fromarray(img_b, mode='RGB')
|
pil_image_b = Image.fromarray(img_b, mode='RGB')
|
||||||
pil_image_mask = Image.fromarray(img_mask, mode='L')
|
pil_image_mask = Image.fromarray(img_mask, mode='L')
|
||||||
|
|
||||||
output_image = Image.composite(pil_image_a, pil_image_b, pil_image_mask)
|
pil_image_a.paste(pil_image_b, (x, y), pil_image_mask)
|
||||||
|
|
||||||
output_array = torch.tensor(np.array(output_image.convert("RGB"))).float() / 255
|
output_array = torch.tensor(np.array(pil_image_a.convert("RGB"))).float() / 255
|
||||||
result[b] = output_array
|
result[b] = output_array
|
||||||
|
|
||||||
return (result,)
|
return (result,)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user