Depth Map Math Combiner
Do actual math on depth maps with a text expression
- depth_map_x
- depth_map_y
- combined_depth
Most depth nodes do one rigid thing. "Depth Map Math Combiner" hands you a text box and a tiny math language, and lets you write the operation yourself. It's the glue node of the ComfyUI-NormalsToDepth pack: take two depth maps, combine or remap them however you like, get one depth map out.
What it's for
Depth maps come from different estimators with different personalities. Depth Anything is the community's default daily driver; Marigold trades speed for maximum sharpness (both get their due in the knowledge base's model rundown). When you want strengths of both, you blend - and a weighted average is the obvious move. Or you want to remap a single map: boost contrast, log-scale it, soften it. This node is that, with an expression instead of a preset dropdown.
How it works
The two depth maps are bound to the names X and Y; the float inputs a and b are also in scope. The expression string is evaluated against a small sandboxed namespace - torch plus a whitelist of log, exp, sqrt, sin, cos, abs, max, min, pow - and the result is clamped to [0,1] so it stays a valid image.
The default a * X + b * Y is a weighted blend: a=0.5, b=0.5 is a 50/50 mix, a=0.7, b=0.3 leans on one source. A few that actually come up:
a * X + (1 - a) * Y # crossfade between the two maps
torch.log(Y + 0.001) # log remap - pulls detail out of the dark end
torch.pow(X, 2) # square - pushes midtones down, more contrast
Inputs and outputs
depth_map_x,depth_map_y- IMAGE. The two sources. The code doesn't resize or validate them, so feed matching dimensions or you're in broadcasting roulette.expression- STRING, defaulta * X + b * Y. This is where you live. UppercaseX/Y- lowercase won't resolve.a,b- FLOAT, -100 to 100, step 0.01. The coefficients the default expression uses.
Output: combined_depth, an IMAGE, clamped to 0–1.
Installing
Same pack, same drill - ComfyUI Manager → search "ComfyUI-NormalsToDepth", or:
cd ComfyUI/custom_nodes
git clone https://github.com/EMkrtchyan/ComfyUI-NormalsToDepth
Restart. Only deps are scipy, numpy, torch; nothing to download, no models to fetch.
Where people get burned
- Silent failure. If your expression errors, the node prints
[DepthMapMathCombiner] Error evaluating expression: ...to the console and quietly returnsXunchanged. You get a "combined" output that is just the first input - no red node, no popup. Watch the console when results look wrong. - Don't get clever. The namespace strips
__builtins__and only exposes those torch functions, so a lot of normal Python won't parse - and when it fails, see the bullet above. Keep expressions to one line of arithmetic. - No shape checking. Mismatched map sizes aren't caught, so you get a broadcasting error (or silent weirdness) instead of a resize. Normalize resolutions before the node, not after.
It's a small, unceremonious pack - the README is one screenshot - but this node is genuinely handy as a depth mixer, and it's a surprisingly fun way to learn what an estimator's maps actually contain by doing math on them.
Inputs (5)
| Name | Type | Default | Description |
|---|---|---|---|
| depth_map_x | IMAGE | — | |
| depth_map_y | IMAGE | — | |
| expression | STRING | a * X + b * Y | — |
| a | FLOAT | 1.00-100–100 | — |
| b | FLOAT | 1.00-100–100 | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| combined_depth | IMAGE | — |