ComfyUI Node Runs on cloud

DepthSlicer

Cut a depth map into layers you can inpaint

By edenartlabΒ·Created 3 years agoΒ·Updated 6 months agoΒ· 119
DepthSlicer
  • image
  • depth_map
  • inpainting_masks
β—„n_slices2β–Ί
β—„rgb_weight0.00β–Ί
β—„standardize_featuresfalseβ–Ί

DepthSlicer is the node that turns a boring grayscale depth map into something you can actually do things with: a stack of binary masks, one per depth layer. If you've ever looked at a depth map and thought "I wish I could grab just the background, or just the foreground," this is the tool. It's the workhorse behind a lot of Eden.art's parallax and depth-separation demos, and it's surprisingly easy to drive.

Depth maps encode distance as brightness - white near, black far, as the depth-estimation essay puts it. What you usually want, though, isn't a gradient, it's separation: a clean cut between "the thing" and "everything behind it." DepthSlicer delivers that by clustering the depth values into n_slices groups and emitting one binary mask per group.

How it works

The clever part is that it doesn't just threshold the depth map into equal bands - it runs weighted K-means clustering over the pixels. Each pixel is represented by its depth value, and optionally its RGB color, and the clusterer groups similar pixels together. The cluster centers are then sorted by depth, so the output masks are ordered back-to-front: mask 0 is the far background, mask n-1 is the nearest foreground.

That rgb_weight input is the secret sauce. Set it to 0 and clustering is pure depth - pixels at the same distance land in the same slice even if they're completely different colors. Crank it up (say 0.3–0.5) and color starts pulling things apart too, so a red car in front of a blue background can separate into its own slice even at a similar depth. standardize_features normalizes the features before clustering; you'll rarely need it, but it can help when depth and color values live on wildly different scales.

The inputs that matter

  • image - the original RGB image (used for the color term).
  • depth_map - grayscale depth image, the thing you'd get from a depth preprocessor like MiDaS or Depth Anything. Bright = close.
  • n_slices (default 2) - how many layers to cut. 2 gives you foreground/background. 4–6 starts to get genuinely useful for parallax and staged outpainting.
  • rgb_weight (default 0) - how much color matters in the clustering, as above.
  • standardize_features - off by default, leave it off.

The single output, inpainting_masks, is a batch of n_slices binary IMAGE masks, one per depth layer.

Where it wires in

This is where the KB's inpainting essay earns its keep: those masks are made to feed a masked inpaint/outpaint pass. The classic Eden workflow is depth slice β†’ mask β†’ repaint each layer independently - regenerate the background with a different prompt, or repaint the foreground object, then composite. Wire inpainting_masks into a node that turns IMAGE masks into latent masks (Set Latent Noise Mask or similar) feeding a KSampler. For pure foreground/background separation at zero cost, set n_slices to 2 and rgb_weight to 0 - instant cutout guide.

Installing

Part of the edenartlab/eden_comfy_pipelines pack (Eden.art nodesuite). One install gets you all 70+ nodes:

cd ComfyUI/custom_nodes
git clone https://github.com/edenartlab/eden_comfy_pipelines.git
cd eden_comfy_pipelines
pip install -r requirements.txt

Or ComfyUI Manager β†’ search "Eden" β†’ install. The clustering uses scikit-learn, which is in the pack's requirements, so no separate install needed.

Gotchas

The masks are binary - each layer is either 0 or 1, no feathered edges. If you're repainting, feather the mask downstream (a few pixels of blur) or you'll see hard seams; the KB's mask-blur guidance applies directly here. Also keep in mind DepthSlicer takes an image depth map, not the output of a ControlNet-preprocessor node's raw tensor - if your depth comes from a MiDaS-style node, make sure it's landing as IMAGE. And the k-means is seeded (random_state=42), so results are reproducible run to run - nice for iterative tuning.

CategoryEden 🌱/Depth

Inputs (5)

NameTypeDefaultDescription
imageIMAGEβ€”
depth_mapIMAGEβ€”
n_slicesINT21–9223372036854776000β€”
rgb_weightFLOAT0.00β€”
standardize_featuresBOOLEANfalseβ€”

Outputs (1)

NameTypeDescription
inpainting_masksIMAGEβ€”