Nodes/ComfyUI-PromptChain/Prompt Chain Background Mask (Depth)
ComfyUI Node

Prompt Chain Background Mask (Depth)

Keep an upscale from sharpening your bokeh

By mobcat40·Created 9 months ago·Updated about a month ago· 15
Prompt Chain Background Mask (Depth)
  • image
  • MASK
bias0.00
softness0.05
feather24

Run a generic detail-adding upscale over a photo with a nicely blurred background and you'll often watch the upscaler fight the photo's own depth of field - sharpening texture into what was supposed to be soft, out-of-focus bokeh. This node exists to stop that: feed it a depth map and it hands back a mask separating near (subject) from far (background), so an upscale pass downstream can hold the background soft while it goes to work on the subject.

How it works

The tooltip on image is explicit about what it expects: a depth map where near is bright, specifically the kind a DepthAnythingV2Preprocessor produces - not a color photo. From that depth map, the node runs Otsu's method, a standard auto-thresholding technique, to find the split point between "subject" and "background" automatically rather than making you dial in a fixed depth value by hand. You get three levers to steer that automatic split rather than override it outright.

The inputs and outputs that matter

bias (default 0, range −0.5 to 0.5) shifts where the automatic split lands. Negative values mask less - pulling only the very farthest planes into "background" - while positive values mask more, pulling nearer planes in too. softness (default 0.05) controls how much depth range around that split point fades gradually instead of cutting hard, which matters because a photo's actual depth of field is itself a gradient, not a binary. feather (default 24px) is a separate, spatial falloff applied after the depth threshold - softening the mask's edges in pixel space rather than depth space, at the resolution of the depth map itself.

Single MASK output. It's meant to feed whatever controls how strongly a detail pass or denoise applies per region - use it, inverted or directly depending on your graph, to hold an upscaler's strength down over the background while it does full work on the foreground subject.

How to install it

Manager: search ComfyUI-PromptChain. Manual:

cd ComfyUI/custom_nodes
git clone https://github.com/mobcat40/ComfyUI-PromptChain.git

You'll also need a depth map to feed it. The pack ships its own license-clean Depth preprocessor bundled in, alongside OpenPose, Canny, Tile, and others, so full ControlNet-style preprocessing works out of the box without a separate dependency on comfyui_controlnet_aux - install PromptChain and you already have what generates this node's input.

Common issues & troubleshooting

The mask includes parts of the subject, or excludes parts of the background. That's bias doing exactly its job in the wrong direction for your image - nudge it toward negative if too much background is getting masked as subject, positive if the reverse.

The split has a visible hard edge where focus falls off gradually in the real photo. Raise softness so the depth-based transition fades rather than cuts.

The mask edge looks jagged or pixel-noisy even though the depth transition itself is fine. That's a spatial issue, not a depth-threshold issue - raise feather, which operates purely in pixel space after the Otsu split has already happened.

You fed it a regular color image instead of a depth map. The Otsu threshold has no meaningful "distance" signal to split on a photo - run your image through a depth preprocessor (the pack's bundled one, or any DepthAnythingV2-style node) first, and feed that output in here.

Categorypromptchain

Inputs (4)

NameTypeDefaultDescription
imageIMAGEDepth map image, near = bright (DepthAnythingV2Preprocessor output).
biasFLOAT0.00-0.5–0.5Shifts the auto (Otsu) subject/background split. Negative masks less (only the farthest planes), positive masks more.
softnessFLOAT0.050–0.5Depth range around the split that fades instead of cutting hard.
featherINT240–512Spatial falloff (px, at the depth map's resolution) applied after thresholding.

Outputs (1)

NameTypeDescription
MASKMASK