Files
xiaden-comfyui-imgutils/node_segment.py
T
xiaden 7d82aa22e6 Full split: 26 dedicated nodes with native knobs exposed
Sub-packages:
- edge/ — Canny, Lineart, LineartAnime (3 nodes)
- restore/ — SCUNet, NAFNet, Adversarial (3 nodes)
- compare/ — CCIP, LPIPS (2 nodes)
- validate/ — Classify (11 ops), Check (5 ops), Metric (2 ops)
- tagging/ — WD14, DeepDanbooru, DeepGelbooru, MLDanbooru, Camie, PixAI (6 nodes)

Root nodes:
- ImgUtilsOCR — PaddleOCR with heat/box threshold
- ImgUtilsDetect — 10 detection types + confidence knob
- ImgUtilsPose — DWPose + auto_detect toggle
- ImgUtilsSegment — isnetis + scale knob
- ImgUtilsTags — tag string processing
- ImgUtilsCDC — upscaling + tile_size
- ImgUtilsCensor — NSFW censoring with method/confidence/body-part toggles
- ImgUtilsAlign — resize to max dimension
- ImgUtilsSqueeze — transparency-based auto-crop

Every node exposes its native function parameters as knobs.
Removed mega-nodes: transform (11 ops), compare (3 ops), validate (18 ops).
2026-07-03 01:11:46 +00:00

70 lines
2.4 KiB
Python

"""
Node 6: ImgUtilsSegment — "Segment character"
Segments character from background using isnetis (anime character segmentation).
Outputs both a mask image and the segmented RGBA image with transparent background.
Uses:
imgutils.segment.isnetis.segment_rgba_with_isnetis() -> (mask: PIL, rgba_image: PIL)
"""
from __future__ import annotations
from comfy_api.latest import io, ui
from .utils import comfy_to_pil, pil_to_comfy
class ImgUtilsSegment(io.ComfyNode):
"""Segment character from background using isnetis."""
@classmethod
def define_schema(cls) -> io.Schema:
return io.Schema(
node_id="ImgUtilsSegment",
display_name="Imgutils Segment",
category="imgutils/segment",
description=(
"Segment anime character from background using isnetis. "
"Outputs the alpha mask and an RGBA image with transparent background."
),
search_aliases=[
"segment", "isnetis", "mask", "character",
"background", "remove bg", "cutout", "alpha",
],
inputs=[
io.Image.Input("image", tooltip="Input image containing character to segment"),
io.Int.Input(
"scale", default=1024, min=256, max=2048, step=128,
tooltip="Processing resolution. Higher = more accurate, slower. Default 1024.",
),
],
outputs=[
io.Mask.Output(display_name="mask"),
io.Image.Output(display_name="segmented_rgba"),
],
)
@classmethod
def execute(cls, image, scale=1024) -> io.NodeOutput:
"""
Run character segmentation and return mask + RGBA image.
Args:
image: ComfyUI IMAGE tensor (B,H,W,C), float32, [0,1]
Returns:
NodeOutput with (mask_tensor, segmented_rgba_tensor)
"""
from imgutils.segment import segment_rgba_with_isnetis
pil_image = comfy_to_pil(image.numpy() if hasattr(image, "numpy") else image)
mask_pil, rgba_pil = segment_rgba_with_isnetis(pil_image, scale=int(scale))
# pil_to_comfy handles grayscale "L" mode (mask) and "RGBA" mode
mask_tensor = pil_to_comfy(mask_pil)
rgba_tensor = pil_to_comfy(rgba_pil)
return io.NodeOutput(mask_tensor, rgba_tensor, ui=ui.PreviewImage(rgba_tensor, cls=cls))