Clean & Repair Depth
Your depth estimator just put a hole in the middle of the face — here's the repair shop
- depth_map
- clean_depth
- repaired_pixels
- report_json
Every monocular depth estimator fails somewhere. Glossy surfaces, sky, transparent stuff - you'll get a zero, a NaN, or a patch of static, and if that patch sits where a person's face should be, it wrecks everything downstream. Clean & Repair Depth is the pre-flight inspection of the ComfyUI-Depth-Visualization pack: it fills holes and kills speckle while trying hard not to blur the edges you actually care about. If you're about to export a mesh or run parallax, this is the node to put between your estimator and everything else.
How it works
Two passes, and it's all classic image processing on CPU tensors - no ML, no downloads.
Fill. Pixels with value at or below hole_threshold (default 0.001, so effectively zeros and nothings) count as holes. Each iteration averages the valid 4-neighbors of every hole and writes the result, then repeats up to fill_iterations (default 3, max 32). The hole literally shrinks from the edges inward, like water filling a crater.
Denoise. If median_radius is above 0, a median filter runs over the filled map - great for suppressing speckle - but here's the trick: preserve_edges (default 0.8) blends the filtered result against the original in proportion to local gradient. Steep edges stay sharp, flat speckle gets smoothed. You get both, and you get to say how much of each.
Inputs and outputs that matter
depth_map- in. Works best after Depth Normalize, though it tolerates raw ranges fine.hole_threshold- how dark counts as "broken." Keep near 0; more on that below.fill_iterations- how aggressively to grow into holes.median_radius- 0 disables denoise entirely; 1 is a good default.preserve_edges- 1.0 keeps every edge, 0.0 lets the median filter flatten everything.
Three outputs, and they're all useful:
clean_depth(IMAGE) - the repaired map. Feed this to the exporters, parallax, or colorize.repaired_pixels(MASK) - exactly which pixels changed. Preview it to see the damage you just fixed, or use it to composite around repaired regions.report_json(STRING) -input_hole_fraction,unfilled_fraction, andchanged_fraction. When the mesh still has a tear, this tells you the hole was bigger than the fills handled.
Install
Same routine as the rest of the pack by gokayfem (Decartunizer, ComfyUI-Texture-Simple). Manager: search ComfyUI-Depth-Visualization, install, restart. Manual:
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, node is under depth/toolkit. Only deps are numpy and Pillow - no weights to fetch, and it runs happily on CPU.
Where people get burned
- Raising
hole_thresholdis a trap. Depth values legitimately sit near 0 for far-away background. If you set the threshold to 0.1 to "catch more junk," you just told the node that half your background is a hole to be filled - it will happily fabricate foreground-colored depth over distant scenery. Keep it near the 0.001 default and letfill_iterationsdo the work. - Median blur is the silent edge-killer.
preserve_edgesfights it, but if your clean output looks soft, check you're not running radius 3+ with preserve_edges at 0. - It's not a magic bullet for huge missing regions. A hole spanning half the image gets filled with neighbor averages, which is a guess. If the damage is structural (a whole object missing), you're better off re-running depth on a different input than trusting the fill. The
repaired_pixelsmask will tell you honestly how much of the image you're inventing.
Inputs (5)
| Name | Type | Default | Description |
|---|---|---|---|
| depth_map | IMAGE | — | |
| hole_threshold | FLOAT | 0.0010–1 | — |
| fill_iterations | INT | 30–32 | — |
| median_radius | INT | 10–5 | — |
| preserve_edges | FLOAT | 0.800–1 | — |
Outputs (3)
| Name | Type | Description |
|---|---|---|
| clean_depth | IMAGE | — |
| repaired_pixels | MASK | — |
| report_json | STRING | — |