Nodes/MTB Nodes/Filter Z (mtb)
ComfyUI Node Runs on cloud

Filter Z (mtb)

Cutting an image by distance instead of by color

By melMass·Created 3 years ago·Updated about a month ago· 723
Filter Z (mtb)
  • image
  • depth
  • IMAGE
to_blacktrue
threshold0.50
inverttrue

"Filter Z" is a nod to the Z-axis - depth, distance from camera - and that's exactly what this node filters on. Instead of masking an image by color, edges, or a hand-drawn mask, you hand it a depth map and it keeps or removes pixels based on how far away they are. Think of it as a cheap, automatic "everything past this distance disappears" tool, the kind of thing you'd reach for to isolate a foreground subject from a busy background, or fake a depth-of-field cutoff without touching a real blur.

Where the depth map comes from

Filter Z doesn't generate depth itself - it consumes one. In a typical ComfyUI setup you'd get that map from a depth estimator like MiDaS, Depth Anything, or ZoeDepth, usually through the ControlNet Auxiliary Preprocessors pack. Those output the standard convention: white is close to the camera, black is far. Filter Z is built to read that convention directly.

Inputs and outputs that matter

  • image - the picture you actually want filtered.
  • depth - the depth map for that same picture (has to line up pixel-for-pixel, so run it through your depth estimator on the same source image).
  • threshold (0–1, default 0.5) - the cutoff point in the depth map's brightness range. This is the one dial you'll actually tune.
  • to_black (default true) - whether filtered-out pixels get replaced with black, versus some other treatment.
  • invert (default true) - flips which side of the threshold gets filtered. With the default true, you're likely keeping one end of the range and dropping the other; if your result looks backwards, this is the first thing to flip.

Output is a single IMAGE - the filtered result, ready to drop straight into a compositing node or feed onward into your pipeline.

Given the defaults on to_black and invert both being true, don't trust your first-glance intuition about "0 = near, 1 = far" - just run it once, look at the result, and flip invert if the wrong side of the scene got cut.

Installing it

  • ComfyUI Manager - search "MTB Nodes", install, restart.
  • Manual - cd ComfyUI/custom_nodes && git clone https://github.com/melMass/comfy_mtb, restart. If you cloned manually, run pip install -r requirements.txt inside the comfy_mtb folder.

Filter Z itself has no model to download - it's pure image math once you've got a depth map in hand. The dependency you actually need is whatever pack is producing that depth map for you (ControlNet Auxiliary Preprocessors is the standard choice).

Common issues & troubleshooting

Result looks completely inverted from what you expected. That's the invert flag doing exactly what it says - toggle it. Depth-map conventions aren't universal across every preprocessor, so don't assume the default matches your source.

Edges look ragged or noisy. Depth estimators aren't pixel-perfect, especially around fine detail like hair or thin objects - the depth map's own imprecision at the threshold boundary shows up directly as ragged edges in the filtered output. A cleaner depth source (Depth Anything tends to have sharper, more consistent edges than older MiDaS variants) helps more than fiddling with threshold.

Some mtb nodes fail to load at startup. That's normal for this pack - check the console for [comfy_mtb] STATUS and visit http://127.0.0.1:8188/mtb for details on what didn't load and why; a handful of mtb's ~100 nodes need optional extras that a default install skips. Filter Z itself is a plain image-processing node, so it's rarely the one on that list.

Categorymtb/filters

Inputs (5)

NameTypeDefaultDescription
imageIMAGE
depthIMAGE
to_blackBOOLEANtrue
thresholdFLOAT0.500–1
invertBOOLEANtrue

Outputs (1)

NameTypeDescription
IMAGEIMAGE