This commit is contained in:
LAOGOU-666
2025-06-01 16:29:55 +08:00
parent 133b9214be
commit 8cf32f0eed
2 changed files with 15 additions and 25 deletions
+14 -24
View File
@@ -380,32 +380,22 @@ class LG_LoadImage(LoadImage):
return LoadImage.IS_CHANGED(image)
def load_image(self, image, keep_alpha=False):
image_path = folder_paths.get_annotated_filepath(image)
# 先调用父类方法获取完整的图像和遮罩
image_tensor, mask_tensor = super().load_image(image)
i = Image.open(image_path)
i = ImageOps.exif_transpose(i)
if keep_alpha:
# 如果需要保持alpha,重新加载为RGBA格式
image_path = folder_paths.get_annotated_filepath(image)
i = Image.open(image_path)
i = ImageOps.exif_transpose(i)
if 'A' in i.getbands():
image = i.convert("RGBA")
image = np.array(image).astype(np.float32) / 255.0
image_tensor = torch.from_numpy(image)[None,]
if keep_alpha and 'A' in i.getbands():
# 保持RGBA格式
image = i.convert("RGBA")
image = np.array(image).astype(np.float32) / 255.0
image = torch.from_numpy(image)[None,]
# 提取alpha通道作为mask
alpha = image[:, :, :, 3]
mask = 1.0 - alpha # ComfyUI中mask的约定:1为遮罩,0为透明
return (image, mask.unsqueeze(0))
else:
# 转换为RGB格式(原有逻辑)
image = i.convert("RGB")
image = np.array(image).astype(np.float32) / 255.0
image = torch.from_numpy(image)[None,]
# 创建空的mask
mask = torch.zeros((image.shape[1], image.shape[2]), dtype=torch.float32, device="cpu")
return (image, mask.unsqueeze(0))
# 遮罩直接使用父类提取的结果,不受keep_alpha影响
return (image_tensor, mask_tensor)
@PromptServer.instance.routes.get("/lg/get/latest_image")
+1 -1
View File
@@ -1,7 +1,7 @@
[project]
name = "comfyui_lg_tools"
description = "This is a toolset designed for ComfyUI by LAOGOU-666, providing a series of practical image processing and operation nodes, making our operation more intuitive and convenient"
version = "1.0.3"
version = "1.0.4"
license = { text = "MIT License" }
dependencies = ["opencv-contrib-python"]