Nodes/ComfyUI-HappNodeSet/Non-White to Black
ComfyUI Node

Non-White to Black

The bluntest instrument in the pack — and sometimes exactly what you need

By mikemojen·Created 8 months ago·Updated 3 months ago· 0
Non-White to Black
  • image
  • image
threshold1.00

Non-White to Black does exactly what its name says and nothing else: every pixel that isn't white becomes solid black. There's no luminance math, no saturation check, no anti-aliasing preservation - it's a hard binary flip. It feels almost too simple for a node, but it earns its place in this pack because there are a lot of times when you want an image reduced to exactly two states before running a contour or path tracer, and this is the one-input, one-knob way to get there.

How it works

A pixel counts as white when all three RGB channels are at or above threshold. The default threshold is 1.0, which on ComfyUI's 0–1 image scale means only pure (255,255,255) survives as white; everything else - light gray, cream, a faint tint - becomes black. Lower the threshold to 0.9–0.95 and near-whites (paper that scanned slightly gray) stay white instead of being flipped.

The output is a single image in what amounts to a black-and-white mask: white where the source was white, black everywhere else. Alpha is preserved through the copy, so transparent regions don't get mangled.

When you'd actually use this

The obvious use is the same as the rest of the cleanup family - feeding a binarized image into LineDetector, ContourGapCloser, or LaserPathTracer so they don't have to guess what "foreground" means. Where this node specifically shines is as a hard mask generator: if you need a silhouette (the object is everything that isn't white), this gives you that in one step, and it's more predictable than a threshold you have to tune per-image. It also pairs well after ColorQuantizer - quantize to a couple of colors, then slam everything that isn't white to black for a brutally clean two-tone result.

The one knob

threshold (0.9–1.0, default 1.0). That narrow range is deliberate: this node is not a "darkness detector," it's a "whiteness detector," and the only question is how strictly you define white. Leave it at 1.0 for exact-white sources; nudge it down only if your "white" background has a scan tint to it. There are no other inputs, and one image output.

Install

It's part of ComfyUI-HappNodeSet (mikemojen). In ComfyUI Manager, search HappNodeSet and install, or:

cd ComfyUI/custom_nodes
git clone https://github.com/mikemojen/ComfyUI-HappNodeSet.git
pip install -r ComfyUI-HappNodeSet/requirements.txt

Restart ComfyUI. Standard pack deps: numpy, OpenCV, scipy, scikit-image, Pillow, torch, svgwrite.

Honest caveats

This node will destroy anti-aliasing - hard edges, no gray - so don't use it when you care about smooth line quality or accurate pixel lengths; that's what Extract Black Advanced with apply_antialiasing is for. And it's a one-way trip: once color is gone, it's gone, so put it after any color-based extraction like Extract Red, not before. Used in the right spot it's the simplest possible thing that produces a usable mask. Used in the wrong spot it's a data-destroying footgun. Both are, technically, working as intended.

Categoryimage/color

Inputs (2)

NameTypeDefaultDescription
imageIMAGE
thresholdFLOAT1.000.9–1

Outputs (1)

NameTypeDescription
imageIMAGE