Nodes/comfyui-tensorop/BackgroundSelect
ComfyUI Node

BackgroundSelect

The node that guesses which mask is the background — and mostly gets it right

By un-seen·Created 2 years ago·Updated 2 years ago· 46
BackgroundSelect
  • mask
  • MASK

Segment anything and you get a stack of masks, but nothing tells you which one is the background. BackgroundSelect's entire job is answering that question with a heuristic: the background is the biggest mask, or failing that, the first mask that touches the edge of the frame. It's a small piece of pure torch arithmetic - no model, no VRAM, instant.

How it works

Feed it a batched mask - a MASK tensor shaped B×H×W, i.e. a stack of per-object masks. The node sums each mask's area, picks the largest one, and checks whether that mask touches any border of the image. If the largest mask doesn't reach a border (say your subject is a huge blob in the middle of the frame), it scans the rest of the batch and grabs the first mask that does. One MASK comes out: the background.

The logic is deliberately simple, and it's the complement of the other mask nodes this pack ships (SeparateMask, ForegroundMask, MaskImage). The typical flow: pull the background mask out so you can keep it untouched while you do something to everything that isn't the backdrop - or invert it and you've got a foreground selector for free.

Where it falls over

It picks by area first, so a giant subject that fills the frame can win even when it never touches a border - the border fallback only kicks in if the largest mask fails the test. Expect correct answers on straightforward scenes and wrong ones on the pathological cases; this is a heuristic, and knowing that is half the battle.

Also worth saying: it deals in hard masks only. If you need fractional alpha for hair or glass, that's matting, not this - reach for something like BiRefNet's matting weights instead. This node answers "which of these blobs is the backdrop," not "how transparent is this pixel."

Install

Same pack as everything else. In ComfyUI Manager, search comfyui-tensorops, or:

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

Restart and you're done. No models, no API keys, no extra dependencies beyond what ComfyUI already has. That's the nicest thing about the tensor-ops half of this pack: the moment you're not talking to the cloud nodes, everything is free, local, and fast.

Categorytensorops

Inputs (1)

NameTypeDefaultDescription
maskMASK

Outputs (1)

NameTypeDescription
MASKMASK