Nodes/ComfyUI WPX Nodes/SplitMaskElements
ComfyUI Node

SplitMaskElements

Cut image elements apart using a mask, not edge detection

By WangPengxing·Created 2 years ago·Updated 2 years ago· 0
SplitMaskElements
  • image
  • mask
  • images
padding10
filtration_area0.0025

SplitMaskElements is SplitStickers' more capable sibling: instead of guessing where things are via edge detection, you hand it a mask that says exactly what's what, and it carves the image into separate elements. This is the node you reach for when the stickers you want to split are on a busy or overlapping background where automatic segmentation would fall apart - or when you already have a mask from something like a segmentation model, SAM, or a threshold node. Give it image + mask, get a list of cleanly separated crops back, ready to feed into the pack's arrangement nodes.

How it works

The node takes your mask, finds its external contours with OpenCV, and treats each contour as one element. Three things happen per element:

  1. Filtering. Contours whose area is below filtration_area (as a fraction of the whole image, default 0.0025 ≈ 0.25%) are dropped - that's how it ignores specks and noise in the mask.
  2. Cropping. Each surviving contour's bounding box is expanded by padding and cut out of the original image.
  3. Alpha. The crop becomes RGBA with the contour itself as the alpha channel - so everything outside that element is transparent, not just a rectangular cut. If the source image already has an alpha channel, both are combined, which keeps existing transparency intact.

That last step is the important one: you get sticker-shaped crops, not boxes with backgrounds, which is exactly what the arrangement nodes need for clean compositing.

The inputs that matter

  • image - the source containing multiple elements.
  • mask - one mask covering all the elements you want separated. Each connected blob in the mask becomes one output.
  • padding (default 10) - extra pixels around each crop. A little padding keeps edges from being shaved; too much adds background junk.
  • filtration_area (default 0.0025) - minimum contour size as a fraction of the image. Raise it to drop smaller stray blobs, lower it to keep tiny elements.

Output: a list of images (OUTPUT_IS_LIST), one per mask blob, wired for a batch-aware consumer or an iterator.

Installing

ComfyUI Manager → search "ComfyUI WPX Nodes" → install → restart. Manual:

cd ComfyUI/custom_nodes
git clone https://github.com/WangPengxing/ComfyUI_WPX_Node
# restart ComfyUI

No models, no requirements file. The pack-wide gotcha again: rtree and scipy are imported at startup, so if either is missing, none of the WPX_Node nodes appear. pip install rtree scipy and restart.

Troubleshooting

  • Overlapping elements merge into one crop. If two blobs in your mask touch or overlap, they're one contour and one output. Keep mask blobs separated for per-element results.
  • A small element vanishes. It fell under filtration_area. Lower the threshold, but expect more noise in exchange.
  • Cropped edges look tight. Raise padding - but note the node caps output quality only by the source resolution, so small crops from a low-res image will look soft when scaled up.
  • Viewer windows pop open. .show() is called per element; on headless setups it just spams the console. Same quirk as SplitStickers.

This pack is a 0.0.1 effort with no real community footprint, so treat it as a handy utility rather than a guaranteed-stable library. For separating objects when you already have a mask, though, it does the job in one node.

CategoryWPX_Node

Inputs (4)

NameTypeDefaultDescription
imageIMAGE
maskMASK
paddingINT100–100
filtration_areaFLOAT0.00250–1

Outputs (1)

NameTypeDescription
imagesIMAGE