Nodes/Refocus - Generative Refocusing/Depth Metric to Relative
ComfyUI Node

Depth Metric to Relative

Make any depth map ControlNet-friendly in one node

By EricRollei·Created 8 months ago·Updated 4 months ago· 19
Depth Metric to Relative
  • depth
  • relative_depth
per_imagetrue
inverttrue
gamma1.00

Depth maps come in two flavors: metric (real distances, like DepthPro's meters) and relative (0–1 ordering - who's near, who's far). The tools that actually consume depth - ControlNet, and most of this pack's defocus math - want the second kind. DepthMetricToRelative converts any raw or metric depth map into a clean 0–1 relative depth, with the usual knobs for orientation and brightness. The README's selling point is right there in the description: it "works with any depth source" - DepthPro, Marigold, MiDaS, whatever you have.

How it works

The conversion does three things in sequence:

  1. Compress with 1/(1+depth) - this is the disparity-style transform that pulls far distances in, so the 0–1 range isn't dominated by a few distant pixels. This is also exactly what the pack's simpler DepthMetricToInverse node does and nothing more; this node is the full version.
  2. Min-max normalize to 0–1, per image or across the batch.
  3. Invert if asked, so near=bright / far=dark - the standard ControlNet convention.

The inputs that matter

  • depth (required) - raw metric or unnormalized depth, grayscale.
  • per_image (true) - normalize each batch image independently. Leave it on unless you specifically want a shared scale across a batch.
  • invert (true) - defaults to the ControlNet convention (near bright, far dark). If your downstream tool expects near=dark, flip it off.
  • gamma (1.0) - brightness bias: >1 brightens midtones, <1 darkens them. This is your practical lever when a depth map looks too flat or too crushed for a given ControlNet weight.

Output: relative_depth (0–1 IMAGE).

When you'd reach for it

Two scenarios, both real:

  • Feeding ControlNet depth - this is the classic pipeline: depth model → DepthMetricToRelative → ControlNet. The KB's depth doc is emphatic that relative depth with crisp edges beats metric depth for conditioning, and the invert=true default matches what ControlNet preprocessors produce.
  • Cleaning up a raw DepthPro output - raw_depth/raw_inverse from DepthPro Estimate are unnormalized (real meters). Run one through this node before it touches anything that assumes 0–1, including this pack's own Compute Defocus Map if you're using raw outputs there.

Gotchas

  • It reads only the first channel of the input, then expands back to three channels. Feeding it an RGB image works (it just uses R), but there's no point - feed it grayscale.
  • The 1/(1+d) step assumes depth is non-negative. A normalized 0–1 map is fine; weird signed ranges will compress oddly.
  • Don't double-convert. If your input is already relative 0–1, this node is harmless but pointless - the min-max normalize becomes a no-op and the inversion might surprise you.

Install

One of the always-available Refocus nodes: ComfyUI Manager ("Refocus - Generative Refocusing") or git clone https://github.com/EricRollei/comfyui-refocus into custom_nodes/, restart. Pure tensor math - no models, no pip extras.

CategoryRefocus/Depth

Inputs (4)

NameTypeDefaultDescription
depthIMAGE
per_imageoptBOOLEANtrueNormalize each image in batch independently
invertoptBOOLEANtrueInvert so near=bright, far=dark (standard for ControlNet)
gammaoptFLOAT1.000.01–10Gamma correction: >1 = brighter midtones, <1 = darker

Outputs (1)

NameTypeDescription
relative_depthIMAGE