From 0e763e880f5e838e7a1e3914444cae6790c48627 Mon Sep 17 00:00:00 2001 From: comfyanonymous Date: Wed, 4 Oct 2023 15:54:34 -0400 Subject: [PATCH] JoinImageWithAlpha now works with any mask shape. --- comfy_extras/nodes_compositing.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/comfy_extras/nodes_compositing.py b/comfy_extras/nodes_compositing.py index f8901eca..68bfce11 100644 --- a/comfy_extras/nodes_compositing.py +++ b/comfy_extras/nodes_compositing.py @@ -3,6 +3,8 @@ import torch import comfy.utils from enum import Enum +def resize_mask(mask, shape): + return torch.nn.functional.interpolate(mask.reshape((-1, 1, mask.shape[-2], mask.shape[-1])), size=(shape[0], shape[1]), mode="bilinear").squeeze(1) class PorterDuffMode(Enum): ADD = 0 @@ -178,6 +180,7 @@ class JoinImageWithAlpha: batch_size = min(len(image), len(alpha)) out_images = [] + alpha = resize_mask(alpha, image.shape[1:]) for i in range(batch_size): out_images.append(torch.cat((image[i][:,:,:3], alpha[i].unsqueeze(2)), dim=2))