ZImage SDNQ Depth Preprocess
The 'use MiDaS' advice, packaged as one node
- image
- image
When you need Z-Image to respect space instead of just lines, depth is the condition you reach for. This node estimates a monocular depth map from a flat photo - how far each pixel is from the camera - and hands you a grayscale image where bright means near and dark means far (or the reverse, if you flip invert). Feed that into ZImageSDNQSamplerControl's control_image and the model will build the scene with the foreground where the foreground was, the background staying behind it.
It's the packaged version of the community's standing advice about depth estimation: "Zoe Depth vs MiDaS? Spoiler alert: use MiDaS." MiDaS isn't the most accurate estimator that exists - Depth Anything and Marigold are - but it's fast, stable, and plenty good enough for a ControlNet condition. And since this is a Z-Image control pipeline, the condition only has to be good enough, because the model is doing the heavy lifting of turning a rough depth field into a coherent image.
The inputs
- model -
MiDaS_small(default),DPT_Hybrid, orDPT_Large. Small is the daily driver: fastest, lowest memory, and for control purposes the quality gap to DPT_Large is rarely visible in the final image. Large is there if you're chasing very intricate geometry. - device - defaults to
cpu, withauto,mps, andcudaavailable. The default is deliberate: depth estimation is a one-time per-image cost and it's fine on CPU. If you're batch-processing a stack of images, set it toautoand let it use your GPU. - invert - the near/far flip. White-near is the convention the control model expects; if your controlled output keeps putting the background where the foreground should be, flip this.
Output is a single image at the input resolution, batch-inclusive - every frame in gets a depth map out.
The model dropdown's first-run caveat: MiDaS and the DPT variants download their weights the first time you use them, typically via torch hub into your torch cache. First queue is slower, then it's cached. Don't panic at the download, panic only if it can't reach the network.
Wiring and gotchas
Same shape as the Canny workflow, just swapped at the preprocessor:
LoadImage → ZImageSDNQDepthPreprocess → ZImageSDNQSamplerControl → PreviewImage
Depth control is more forgiving than Canny - it constrains layout without pinning down every edge - which makes it the better choice for organic subjects, portraits, and scenes where you want the composition locked but the details loose. Canny is for hard structure, depth is for spatial relationships.
Two things that bite people. First, depth maps are grayscale by definition but the node outputs a 3-channel image, so it plugs straight into the control sampler - don't try to convert or channel-squeeze it yourself. Second, there's no "correct" absolute depth here; the map gets normalized to 0–1 before it reaches the model. If the output looks depth-blind, the fix is almost always invert, not the model choice.
Install is identical to the rest of the pack (Manager, or git clone https://github.com/GeneralShan/comfyui-zimage-sdnq into custom_nodes). Depth is the one preprocessor that pulls MiDaS in through the integrations/midas.py shim, so a clean first-run download is expected. If depth estimation itself ever errors, check that torch hub can reach the internet once, then it's cached forever.
Inputs (4)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| model | COMBO | MiDaS_small | 3 options: MiDaS_small, DPT_Hybrid, DPT_Large |
| device | COMBO | cpu | 4 options: cpu, auto, mps, cuda |
| invert | BOOLEAN | false | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| image | IMAGE | — |