resolved issue with black and white images in nodes_mask.py

Nodes that use the composite function accept both bw and rgb images. Both formats correctly display in the image preview node, however, the formats have transposed HW and incompatible C dimensions, even though they are both accepted as inputs. 

This change introduces a function that converts black and white inputs to rgb so that composite operations do not unexpectedly fail while the image preview displays an image successfully.
This commit is contained in:
shawnington 2024-07-25 19:46:04 -04:00 committed by GitHub
parent 61a2b00bc2
commit 1df031d82b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -5,7 +5,19 @@ import comfy.utils
from nodes import MAX_RESOLUTION
def tensor_to_rgb(img):
# convert from bw to rgb : cwh -> bchw
if img.shape[1] != 3:
if len(img.shape) == 3:
img = img.unsqueeze(0)
img = img.permute(0, 1, 3, 2).repeat(1, 3, 1, 1)
return img
def composite(destination, source, x, y, mask = None, multiplier = 8, resize_source = False):
destination = tensor_to_rgb(destination)
source = tensor_to_rgb(source)
source = source.to(destination.device)
if resize_source:
source = torch.nn.functional.interpolate(source, size=(destination.shape[2], destination.shape[3]), mode="bilinear")