Nodes/ComfyUI_KimNodes/🍒Split_Mask🔪蒙版元素分割
ComfyUI Node

🍒Split_Mask🔪蒙版元素分割

Slice every element out onto its own transparent canvas

By wjl0313·Created 2 years ago·Updated 12 months ago· 54
🍒Split_Mask🔪蒙版元素分割
  • image
  • mask
  • images
padding10
filtration_area0.0025

Ever generated a mask that has several separate objects in it and wished you could just pull each one out? Split_Mask does exactly that: it looks at the connected regions in a mask and returns every one as its own image, cut to its bounding box on a transparent background.

It's the node you reach for when a sprite sheet, a group render, or a multi-subject segmentation mask needs to become individual elements. Downstream you can process each cutout separately - inpaint one, upscale one, feed one to a per-image loop - then composite them back later. The pack is built around this pattern: Split_Mask produces elements, Transparent_Image_Filter drops the empty ones, Seamless_Tiling_Generator or Crop_Paste reassembles them.

The mechanism. It's classic OpenCV blob detection, dressed up for ComfyUI. The mask is binarized (threshold 127), cv2.findContours finds the outer contours of each separate region, and each contour gets its own bounding box. Two parameters shape the output: padding adds a border of pixels around each cut so elements don't sit right on the crop edge, and filtration_area drops any contour whose area is smaller than that fraction of the whole image - your noise filter for tiny speckles. Each region is then rendered onto a transparent RGBA canvas using the contour itself as the alpha channel, so you get clean cutouts, not rectangular chips.

Inputs. Four, and you'll tune two:

  • image - the source image.
  • mask - the segmentation mask labeling the objects.
  • padding - INT, default 10, range 0–100. Pixels of breathing room around each element. 10 is a good starting point; crank it if you're about to apply edge effects that need margin.
  • filtration_area - FLOAT, default 0.0025, range 0–1. The minimum blob size as a fraction of image area. 0.0025 means "ignore anything smaller than 0.25% of the image." If you're getting garbage micro-elements, raise it; if a legitimately small object keeps vanishing, lower it.

Output. images - an IMAGE list of the cutouts, one per detected region, in the order the contours were found.

Where people get burned. The 127 threshold is fixed - a soft, gradient mask gets binarized, and faint regions can split into multiple blobs or vanish. If your mask came from a segmentation model with feathered edges, threshold it to a crisp black/white mask upstream (the pack's Mask_Noise_Cleaner exists for exactly this cleanup job). Also note it expects a proper MASK tensor; feed it the mask output of a segmentation or background-removal node, not a raw image. And because output order follows contour detection, "which one is index 0" isn't guaranteed to be reading order - the pack's YOLO nodes sort properly, this one doesn't.

Install. It's part of KimNodes (wjl0313's 🍒 toolbox on the Comfy registry). ComfyUI Manager → search "ComfyUI_KimNodes", or:

cd ComfyUI/custom_nodes
git clone https://github.com/wjl0313/ComfyUI_KimNodes

then restart. One real dependency to know about: this node imports cv2. The pack's requirements.txt only lists pixeloe, so on a fresh environment you'll often need pip install opencv-python before Split_Mask loads. A missing import shows up as the node refusing to render in the graph - that's the fix.

Troubleshooting. If it outputs nothing, your mask is probably empty after binarization - check the mask's values, or raise filtration_area to 0 if even tiny specks should count. If cutouts come out cramped, raise padding. If elements are bleeding into each other, your mask regions are touching - you need a mask with separated blobs before splitting.

Category🍒 Kim-Nodes/🔲Mask_Tools | 蒙板工具

Inputs (4)

NameTypeDefaultDescription
imageIMAGE
maskMASK
paddingINT100–100
filtration_areaFLOAT0.00250–1

Outputs (1)

NameTypeDescription
imagesIMAGE