Nodes/comfyui-tensorop/SeparateMask
ComfyUI Node

SeparateMask

One Mask, Many Objects — Cut Each One Out on Its Own Port

By un-seen·Created 2 years ago·Updated 2 years ago· 46
SeparateMask
  • image
  • mask
  • bboxes
  • MASK
  • IMAGE

Segmentation models love to give you everything at once: one mask that covers four objects, or a mask per region with no clean way to separate them. Then you want to inpaint or detail each object individually, and you're stuck splitting masks by hand. SeparateMask is the "un-group" button. Give it an image, a mask, and a list of bounding boxes, and it hands you back a per-object mask and a cropped element image for every box - batched, aligned, ready to wire into separate passes.

How it works

For each bounding box it crops that region out of both the image and the mask, then applies the mask to the crop's alpha channel so the object is cut out on a transparent background. Two things come out, indexed to match the order of your boxes:

  • MASK - a full-canvas mask per element, with the element's mask placed back at its original coordinates on a white field. These wire straight into anything that takes a mask: an inpaint pass, a detailer, a compositor.
  • IMAGE - the cropped RGBA element, padded to a uniform canvas so the whole batch shares one size and stacks cleanly in torch.cat.

Under the hood it's numpy and scipy.ndimage for the region math, PIL for the cropping and compositing, and a couple of torchvision transforms to hand the results back as tensors. Nothing exotic, nothing to download.

The three inputs

  • image (IMAGE) - the full image you're cutting objects out of.
  • mask (MASK) - the segmentation mask covering everything. One mask can cover many objects; the boxes tell the node where each one lives.
  • bboxes (BBOX) - the list of bounding boxes. The BBOX type comes from detection nodes; the classic source is Impact Pack's BboxDetector / UltralyticsDetectorProvider, which output boxes as (x1, y1, x2, y2) pixel coordinates. Your detector's box format has to match the image dimensions - this node does no rescaling.

The two inputs you'll actually fiddle with are image and bboxes. The mask does the cutting; the boxes do the splitting.

Where people get burned

  • Polarity matters and there's no flip switch. The node applies your mask to the alpha channel as-is and expects a specific orientation. If your elements come out inverted - object transparent, background solid - flip the mask upstream (there are plenty of invert/invert-mask nodes, including ComfyUI core's). Preview the output before you build a big pipeline on top of it.
  • Tiny boxes get silently dropped. Regions under roughly 1000 px² are filtered out, and the node doesn't tell you. If an object "disappears," that's why.
  • The IMAGE output is padded, not rescaled. Everything is centered on a canvas the size of the largest box. A small object stays small on a big transparent canvas - don't expect uniform pixel sizes, and don't feed these into something that assumes square tiles.
  • Box format is on you. Wrong coordinate order or boxes from a model that outputs x, y, w, h instead of x1, y1, x2, y2 will crop garbage. Confirm against your detector's docs.

Installing it

It ships in the un-seen/comfyui-tensorops pack. In ComfyUI Manager, search comfyui-tensorops and install, or clone it by hand:

cd ComfyUI/custom_nodes
git clone https://github.com/un-seen/comfyui-tensorops

then restart ComfyUI. One warning: this is a light node in a heavy pack. Installing it drags in transformers, boto3, redis, fal-client, replicate, and surrealist, plus scipy - fine if you want the whole pack, annoying if you only wanted one mask-splitting utility. And the pack has a reputation footnote: it previously registered node names identical to Kijai's Florence2 nodes, which confused ComfyUI Manager's auto-install back in 2024. Install it deliberately, not via "install missing nodes" on a random workflow.

The pattern it unlocks

This is the standard detect → split → process-each pipeline, minus the hand-rolling. A detector gives you boxes, a segmentation node gives you one mask, SeparateMask splits it, and each object gets its own inpaint or refine pass. For product shots, character sheets, or any "fix this one object, leave the rest alone" job, it turns a fiddly multi-step chore into three nodes. Just check the polarity first - that's the whole game.

Categorytensorops

Inputs (3)

NameTypeDefaultDescription
imageIMAGE
maskMASK
bboxesBBOX

Outputs (2)

NameTypeDescription
MASKMASK
IMAGEIMAGE