From a268fe57edcb8cd968d6af93778a76c6fee678d5 Mon Sep 17 00:00:00 2001 From: kk8bit Date: Wed, 12 Mar 2025 15:14:51 +0800 Subject: [PATCH] v0.26.1 --- nodes/preview_mask_plus.py | 10 +++++----- pyproject.toml | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/nodes/preview_mask_plus.py b/nodes/preview_mask_plus.py index cfcec22..82f42b9 100644 --- a/nodes/preview_mask_plus.py +++ b/nodes/preview_mask_plus.py @@ -19,6 +19,7 @@ class PreviewMaskPlus(SaveImage): def INPUT_TYPES(cls): return { "required": { + "invert_mask": ("BOOLEAN", {"default": False, "tooltip": "Invert mask values (0->1, 1->0)"}), "Preview": (["none", "image", "mask", "Black", "White", "Gray", "Red", "Green", "Blue"],), "image": ("IMAGE", {}), "mask": ("MASK", {}), @@ -30,16 +31,14 @@ class PreviewMaskPlus(SaveImage): FUNCTION = "execute" CATEGORY = "KayTool/Mask" - def execute(self, Preview, image, mask, filename_prefix="ComfyUI", prompt=None, extra_pnginfo=None): + def execute(self, invert_mask, Preview, image, mask, filename_prefix="ComfyUI", prompt=None, extra_pnginfo=None): device = comfy.model_management.get_torch_device() - # Ensure image is in the correct format image = image.permute([0, 3, 1, 2]) image = image.permute([0, 2, 3, 1]) foreground = image[:, :, :, :3] if image.shape[3] == 4 else image foreground = foreground.to(device) - # Ensure mask is in the correct format if not isinstance(mask, torch.Tensor): raise ValueError("Input mask must be a PyTorch tensor.") if mask.dim() not in [2, 3]: @@ -52,7 +51,9 @@ class PreviewMaskPlus(SaveImage): mask = mask.unsqueeze(0) mask = mask.to(device) - # Resize mask to match image dimensions + if invert_mask: + mask = 1. - mask + target_height, target_width = foreground.shape[1], foreground.shape[2] mask_height, mask_width = mask.shape[1], mask.shape[2] if mask_height > target_height: @@ -63,7 +64,6 @@ class PreviewMaskPlus(SaveImage): padding = (0, max(0, target_width - mask_width), 0, max(0, target_height - mask_height)) mask = F.pad(mask, padding, "constant", 0) - # Generate preview based on selected option if Preview == "image": preview = foreground elif Preview == "mask": diff --git a/pyproject.toml b/pyproject.toml index 45bf796..8c633f3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,7 @@ [project] name = "kaytool" description ="KayTool nodes boost ComfyUI workflow efficiency with practical tools: BiRefNet/RemBG for background/mask tasks, wireless data transfer (Get & Out), AI translation (Tencent/Baidu), dynamic math operations, image processing (size, color, blur, expand), flexible text handling, precision sliders, metadata-supported image saving, quick Run options via right-click (Run Group/Node), load image folder, and more." -version = "0.26.0" +version = "0.26.1" license = {file = "LICENSE"} dependencies = ["rembg"]