ComfyUI Node

Extract Red

Isolate the red markup, kill everything else — before anything else tries to read your diagram

By mikemojen·Created 8 months ago·Updated 3 months ago· 0
Extract Red
  • image
  • image
red_threshold0.40
red_dominance0.20
max_other_channels1.00
preserve_original_redtrue
invert_outputfalse

If you've ever fed a marked-up drawing into a line detector and watched it try to count your red annotation strokes as actual lines, you already know why this node exists. Extract Red does one thing: it turns every pixel that isn't "red enough" into pure white, leaving you with only the red markings on a clean background. It's the sibling of the pack's Extract Black, aimed at the opposite job - pulling annotations, corrections, or highlighted regions out of a diagram so the rest of the pipeline stops tripping over them.

How it works

This is a per-pixel color test, not a model, and it's fast enough to run on anything. A pixel counts as "red" when three conditions hold at once: the red channel is at least red_threshold, red beats the higher of green and blue by at least red_dominance, and both green and blue stay under max_other_channels. Every pixel that fails the test becomes white. Everything that passes keeps its original color (or gets flattened to pure (1,0,0) red if you turn off preserve_original_red).

That three-way check is what separates "red" from "orange" and "pink." A salmon-colored fill can have a high red channel, but it also has green and blue high enough that it fails the dominance test. If you're finding yellow or pink sneaking through, tighten red_dominance and lower max_other_channels; if your reds are faded or light, lower red_threshold from its 0.4 default.

The inputs that matter

  • red_threshold (0–1, default 0.4) - how bright red must be. 0.0 means "any hint of red," 1.0 means "pure red only."
  • red_dominance (0–1, default 0.2) - how much red must outrank green/blue. This is your "redness" knob.
  • max_other_channels (0–1, default 1.0) - cap on green and blue. Lower it for purer reds.
  • invert_output - swaps to a white-on-red output if some later node wants that.

The single output, image, wires straight into the pack's LineDetector or RasterToUniformSVG, or anywhere else that expects a clean binary-ish image.

Install

Extract Red ships inside ComfyUI-HappNodeSet (author mikemojen, "Happrecision"), so you get the whole pack - the line counter family, the SVG tools, the laser-path stuff. ComfyUI Manager: search HappNodeSet and install. Manual:

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

Then restart ComfyUI. The deps are numpy, OpenCV, scipy, scikit-image, Pillow, torch, and svgwrite - nothing exotic, though if your venv is already battle-scarred from other nodes, that's the usual spot for conflicts (the classic custom-node dependency dance, as the ecosystem docs love to warn about).

Common issues

The main gotcha is the opposite of what you'd expect: too strict detection. Red pen scans badly - cheap red ink reads more like a dark maroon, and your red strokes can vanish entirely at the defaults. Drop red_threshold toward 0.25–0.3 for scanned pencil-and-red markup. Second gotcha: antialiased edges. A red stroke blended over white produces pink edges that fail the dominance test and stay white, giving you slightly thinned lines. That's usually fine before a skeletonizer, but if you're measuring lengths, don't be surprised by a small underestimation. Run a quick Preview Image node on the output before committing to downstream numbers - the whole point of this node is that what you see is what gets measured.

Categoryimage/processing

Inputs (6)

NameTypeDefaultDescription
imageIMAGE
red_thresholdFLOAT0.400–1Minimum red channel value required (0.0 = any red, 1.0 = pure red only)
red_dominanceFLOAT0.200–1How much the red channel must exceed green and blue (0.0 = no dominance required, higher = stricter)
max_other_channelsoptFLOAT1.000–1Maximum allowed value for green and blue channels (lower = purer reds only)
preserve_original_redoptBOOLEANtrueIf enabled, keeps original red pixel colors; if disabled, converts red pixels to pure red (1,0,0)
invert_outputoptBOOLEANfalseIf enabled, outputs white background with inverted colors

Outputs (1)

NameTypeDescription
imageIMAGE