From 63917709c1b78a0a88358f06a59c0b831d316b4b Mon Sep 17 00:00:00 2001 From: William Gill Date: Sun, 19 Apr 2026 16:40:39 -0500 Subject: [PATCH] smart_image_gen v0.7.6: feather inpaint mask edges via GrowMask MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The raw SAM mask is a hard binary edge — KSampler repaints right up to it, and SDXL has no surrounding-pixel context inside the mask to blend with. Result: the inpainted region looks pasted-on with visible seams (the artifact the user reported on the werewolf-groin edit). Inserted a stock GrowMask node (id 17) between GroundingDinoSAMSegment and SetLatentNoiseMask: - expand=12 grows the mask outward by 12 px so the new content overlaps a strip of original pixels for blending - tapered_corners=True softens the edge so the noise transition isn't a step function GrowMask is built into stock ComfyUI; no extra custom node install. KSampler still uses the caller-supplied denoise (default 1.0 in inpaint mode). Co-Authored-By: Claude Opus 4.7 (1M context) --- .../ai-stack/openwebui-tools/smart_image_gen.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/deployments/ai-stack/openwebui-tools/smart_image_gen.py b/deployments/ai-stack/openwebui-tools/smart_image_gen.py index 51a37b7..b65110a 100644 --- a/deployments/ai-stack/openwebui-tools/smart_image_gen.py +++ b/deployments/ai-stack/openwebui-tools/smart_image_gen.py @@ -1,7 +1,7 @@ """ title: Smart Image Generator & Editor (ComfyUI) author: ai-stack -version: 0.7.5 +version: 0.7.6 description: Generate or edit images via ComfyUI with automatic SDXL checkpoint routing. Two methods — generate_image (txt2img) and edit_image (img2img on the user's most recently attached image). The @@ -303,6 +303,13 @@ def _build_inpaint(positive: str, negative: str, settings: dict, "the dog's collar"), then SetLatentNoiseMask + KSampler repaint only that region. Everything outside the mask stays pixel-perfect. + The raw SAM mask is run through GrowMask with tapered_corners + before it reaches the sampler. Without that, the mask edge is + pixel-binary and KSampler repaints right up to a hard boundary — + SDXL has no surrounding-pixel context inside the mask to blend + with, so the inpainted region looks pasted-on with visible seams. + expand=12px + taper gives a soft transition that blends naturally. + First inpaint downloads ~3 GB of SAM/GroundingDINO weights into /opt/comfyui/models/{sams,grounding-dino}/ — subsequent runs reuse them. @@ -329,7 +336,7 @@ def _build_inpaint(positive: str, negative: str, settings: dict, "11": {"class_type": "VAEEncode", "inputs": {"pixels": ["12", 0], "vae": ["4", 2]}}, "12": {"class_type": "LoadImage", "inputs": {"image": image_filename}}, "13": {"class_type": "SetLatentNoiseMask", - "inputs": {"samples": ["11", 0], "mask": ["16", 1]}}, + "inputs": {"samples": ["11", 0], "mask": ["17", 0]}}, "14": {"class_type": "SAMModelLoader (segment anything)", "inputs": {"model_name": "sam_hq_vit_h (2.57GB)"}}, "15": {"class_type": "GroundingDinoModelLoader (segment anything)", @@ -342,6 +349,12 @@ def _build_inpaint(positive: str, negative: str, settings: dict, "prompt": mask_text, "threshold": 0.3, }}, + "17": {"class_type": "GrowMask", + "inputs": { + "mask": ["16", 1], + "expand": 12, + "tapered_corners": True, + }}, }