mirror of
https://github.com/comfyanonymous/ComfyUI.git
synced 2025-04-20 03:13:30 +00:00
Fix alpha image issue in more nodes.
This commit is contained in:
parent
2222cf67fd
commit
3d2e3a6f29
@ -2,6 +2,7 @@ import numpy as np
|
|||||||
import scipy.ndimage
|
import scipy.ndimage
|
||||||
import torch
|
import torch
|
||||||
import comfy.utils
|
import comfy.utils
|
||||||
|
import node_helpers
|
||||||
|
|
||||||
from nodes import MAX_RESOLUTION
|
from nodes import MAX_RESOLUTION
|
||||||
|
|
||||||
@ -87,11 +88,7 @@ class ImageCompositeMasked:
|
|||||||
CATEGORY = "image"
|
CATEGORY = "image"
|
||||||
|
|
||||||
def composite(self, destination, source, x, y, resize_source, mask = None):
|
def composite(self, destination, source, x, y, resize_source, mask = None):
|
||||||
if destination.shape[-1] < source.shape[-1]:
|
destination, source = node_helpers.image_alpha_fix(destination, source)
|
||||||
source = source[...,:destination.shape[-1]]
|
|
||||||
elif destination.shape[-1] > source.shape[-1]:
|
|
||||||
destination = torch.nn.functional.pad(destination, (0, 1))
|
|
||||||
destination[..., -1] = source[..., -1]
|
|
||||||
destination = destination.clone().movedim(-1, 1)
|
destination = destination.clone().movedim(-1, 1)
|
||||||
output = composite(destination, source.movedim(-1, 1), x, y, mask, 1, resize_source).movedim(1, -1)
|
output = composite(destination, source.movedim(-1, 1), x, y, mask, 1, resize_source).movedim(1, -1)
|
||||||
return (output,)
|
return (output,)
|
||||||
|
@ -6,7 +6,7 @@ import math
|
|||||||
|
|
||||||
import comfy.utils
|
import comfy.utils
|
||||||
import comfy.model_management
|
import comfy.model_management
|
||||||
|
import node_helpers
|
||||||
|
|
||||||
class Blend:
|
class Blend:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
@ -34,6 +34,7 @@ class Blend:
|
|||||||
CATEGORY = "image/postprocessing"
|
CATEGORY = "image/postprocessing"
|
||||||
|
|
||||||
def blend_images(self, image1: torch.Tensor, image2: torch.Tensor, blend_factor: float, blend_mode: str):
|
def blend_images(self, image1: torch.Tensor, image2: torch.Tensor, blend_factor: float, blend_mode: str):
|
||||||
|
image1, image2 = node_helpers.image_alpha_fix(image1, image2)
|
||||||
image2 = image2.to(image1.device)
|
image2 = image2.to(image1.device)
|
||||||
if image1.shape != image2.shape:
|
if image1.shape != image2.shape:
|
||||||
image2 = image2.permute(0, 3, 1, 2)
|
image2 = image2.permute(0, 3, 1, 2)
|
||||||
|
@ -44,3 +44,11 @@ def string_to_torch_dtype(string):
|
|||||||
return torch.float16
|
return torch.float16
|
||||||
if string == "bf16":
|
if string == "bf16":
|
||||||
return torch.bfloat16
|
return torch.bfloat16
|
||||||
|
|
||||||
|
def image_alpha_fix(destination, source):
|
||||||
|
if destination.shape[-1] < source.shape[-1]:
|
||||||
|
source = source[...,:destination.shape[-1]]
|
||||||
|
elif destination.shape[-1] > source.shape[-1]:
|
||||||
|
destination = torch.nn.functional.pad(destination, (0, 1))
|
||||||
|
destination[..., -1] = source[..., -1]
|
||||||
|
return destination, source
|
||||||
|
Loading…
Reference in New Issue
Block a user