Depth Range Masks
Want to relight the foreground without touching the sky? This is your selection tool
- depth_map
- inside_range
- outside_range
- masked_depth
Depth is a selection tool nobody advertises as one. You want to relight the person without blowing out the background, or replace the sky while keeping the foreground intact, or isolate the near plane for a depth-conditioned generation pass. Grabbing that with an image-space mask is fiddly. Depth Range Masks hands it to you in three outputs: soft near/far masks and the masked depth, straight out of the ComfyUI-Depth-Visualization pack (gokayfem, the author behind Decartunizer).
How it works
This one is refreshingly simple under the hood. The node treats depth as a 0–1 value axis and marks every pixel whose depth lands between near and far as "inside." feather (default 0.02) turns the hard edges into smooth ramps, so you don't get a hard cut line across the image - masks ease in over the feather width. The result is a proper soft mask you can feed straight into compositing, IC-Light-style relighting, or inpainting.
invert_depth exists for the same reason every node in this pack has it: depth estimators disagree about which end is white. Flip it if your map comes out inverted and your near/far bands land on the wrong half of the scene.
Inputs and outputs that matter
depth_map- in. Normalize first; the near/far values are meaningful in[0,1]space.near(0.2) /far(0.8) - the depth slab you're selecting. Narrower band = tighter selection.feather(0.02) - transition softness. Bump it if you see banding where your mask meets the unselected region.invert_depth- flips the axis.
Three outputs, and this is where the node earns its keep:
inside_range(MASK) - the band you asked for. Wire into a mask input on relight, compositing, or ControlNet conditioning to restrict it to a depth slab.outside_range(MASK) - its complement, always. Select background to replace, foreground untouched.masked_depth(IMAGE) - the depth map with everything outside the band zeroed out. Perfect for feeding a depth-ControlNet that should only see part of the scene.
Install
Manager: search ComfyUI-Depth-Visualization, install, restart. Manual, same as every node in the pack:
cd ComfyUI/custom_nodes
git clone https://github.com/gokayfem/ComfyUI-Depth-Visualization.git
python -m pip install -r ComfyUI-Depth-Visualization/requirements.txt
Restart, look under depth/toolkit. Deps are numpy and Pillow only - no models, no downloads, CPU-friendly.
Where people get burned
farmust be greater thannear- the node raisesValueErrorif you invert them. The most common stumble by far.- The bands are on the depth axis, not the distance axis. White-near maps read naturally; if your estimator is white-far, your "near" selection grabs the horizon. That's what
invert_depthis for - use it. - Zero feather gives you edges, not cutouts. A hard mask aliases when you downscale or feather later in compositing. If it's for relighting or inpainting, a small feather (0.02–0.05) hides the seam. If you genuinely want a hard selection for a mask-blended ControlNet, that's what 0 is for.
- Feed it normalized depth. Near/far are interpreted against raw values; an un-normalized map with range 0–5 makes
0.2/0.8select almost nothing. Depth Normalize first, always.
Inputs (5)
| Name | Type | Default | Description |
|---|---|---|---|
| depth_map | IMAGE | — | |
| near | FLOAT | 0.200–1 | — |
| far | FLOAT | 0.800–1 | — |
| feather | FLOAT | 0.0200–0.5 | — |
| invert_depth | BOOLEAN | false | — |
Outputs (3)
| Name | Type | Description |
|---|---|---|
| inside_range | MASK | — |
| outside_range | MASK | — |
| masked_depth | IMAGE | — |