Get Better Depth Image @Liam
A crude 'pick the richer depth map' tiebreaker
- image1
- image2
- IMAGE
Depth maps are a staple of modern workflows: a grayscale image where brightness encodes distance, used to guide ControlNet conditioning, parallax effects, and 3D displacement. The ecosystem has several ways to produce one - MiDaS, Depth Anything, Marigold - and if you're running two of them side by side, you'll occasionally want a quick way to pick which result to keep. That's the entire job of this node: give it two depth maps, and it returns the one it considers "better."
Let me be straight about what "better" means, because it's not what you'd hope. There's no AI, no learned quality model, no fusion. The node counts bright pixels - specifically, pixels with intensity above a hardcoded threshold of 200 - and returns whichever input has more of them. That's the whole heuristic. The theory is that a depth map with more near-white pixels is "fuller" or has more content. It's a tiebreaker, not an evaluation.
Inputs and outputs
Two required inputs, both IMAGE tensors: image1 and image2. One output: IMAGE - either image1 or image2, unchanged, based on the count. There are no knobs: the 200 threshold and the histogram range (50–200) are baked into the code.
How it works
For each input it computes a histogram of pixel intensities via OpenCV, sums the count of pixels above 200, and picks the larger sum. That's implemented in lib_utils.compare_image_levels_bast - and yes, "bast" is in the actual source, alongside some Chinese comments; this is a personal-toolkit node and it shows.
Installing it
Part of LiamUtil:
cd ComfyUI/custom_nodes
git clone https://github.com/ai-liam/comfyui-liam
pip install -r requirements.txt
or via ComfyUI Manager (search LiamUtil) + restart. The opencv-python dependency is the one it actually leans on.
Where people get burned
The honest advice: don't let the name oversell it. "More bright pixels" is not "more accurate depth," and it can actively pick the wrong map. A depth estimator that returns a decent scene often has large dark regions (far background), while a noisy or washed-out map can have more pixels pushed toward white - and this node would pick the noisy one. Brightness-counting also falls apart on mostly-dark maps, where the comparison is basically a coin flip. Where it does make sense: comparing two variants from the same pipeline where you've observed one consistently looks richer, or as a quick "keep whichever isn't broken" gate before feeding a ControlNet. If you actually need the best depth map, A/B test the estimators yourself (the community consensus has long favored MiDaS edges for ControlNet work, with Depth Anything V2 the current default) rather than trusting a pixel counter.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| image1 | IMAGE | — | |
| image2 | IMAGE | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| IMAGE | IMAGE | — |