mirror of
https://git.datalinker.icu/comfyanonymous/ComfyUI
synced 2026-11-20 21:07:08 +08:00
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:
parent
61a2b00bc2
commit
1df031d82b
@ -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")
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user