Line Region Detector
Teaching ComfyUI what's a line and what's a fill
- image
- line_mask
- fill_mask
- preview_image
- color_info
Line Region Detector is the front door of the TJ_ComfyUI_Lineart2Vector pipeline: you feed it the line-art image, it hands back the masks that Centerline to SVG needs. It answers one question - which pixels are the ink? - and it does it in a way that separates the lines from the fills, which turns out to matter more than you'd think.
Why separate lines from fills?
Most line art isn't just outlines. An anime cel or a comic page has thick black outlines around regions that are filled with color or solid black (a pupil, a shadow block, a solid background). If you vectorized everything indiscriminately you'd get a filled silhouette instead of clean strokes - useless for a laser cutter or a plotter. This node's job is to hand you two masks: line_mask (the actual strokes) and fill_mask (the solid regions), plus a preview_image overlay and a color_info JSON.
How it works
From the source, the flow is: grayscale conversion → background separation → line detection → fill separation. Background separation respects your background_mode (auto, white, or black - most line art is white-background, which is why the default background_threshold is 240). Then line detection runs one of three methods:
edge- edge detection on the foreground, dilated into line regions.morphology- erodes the foreground and subtracts the result from itself, which isolates the thin stroke regions from the thick fill areas.hybrid- morphology first, falling back to edge if it finds little, then a closing pass to stitch gaps. This is the one to reach for when you're not sure what your art needs.
min_line_width / max_line_width bracket what counts as a "line" (defaults 1–50px). fill_handling decides what happens to fills: ignore them, separate them into their own mask (the useful default for the pipeline), or fold them included into the line mask.
Optional color_clustering (+ num_colors, default 5) quantizes the colors in the art and reports them through color_info - that's what feeds Centerline to SVG's preserve_colors if you want the SVG to keep original stroke colors instead of everything coming out black.
The inputs a beginner actually touches
Honestly, only a few: image, background_mode (switch auto → white if your art is on white), line_detection_method (start with hybrid if edge gives you broken lines), and fill_handling (leave at separate). Everything else has sane defaults.
Outputs: line_mask (MASK) → wire into Centerline to SVG or Mask Line Cleanup. fill_mask (MASK) → save it or ignore it. preview_image → stick it on a preview node to see what got detected, because you will want to eyeball this before vectorizing. color_info → optional color metadata for later.
Install + gotchas
Pack-wide install (no models, no keys - pure local CV):
cd ComfyUI/custom_nodes
git clone https://github.com/TJ16th/TJ_ComfyUI_Lineart2Vector.git
# restart
or ComfyUI Manager → search TJ_ComfyUI_Lineart2Vector. The requirements.txt wants opencv-python and opencv-contrib-python, scikit-image, scipy, Pillow, numpy, torch - nearly all preinstalled with ComfyUI.
Where people get burned: on gray or off-white backgrounds, background_threshold at 240 flags the background as foreground - drop it. On very thin antialiased lines, edge mode can fragment strokes into dashes; that's what min_line_width and hybrid mode are for. And if your "line art" is actually a clean flat-color illustration, remember this node separates lines from fills by width, so thick stylized strokes may land in fill_mask. Check preview_image before you trust the masks - that habit saves everyone a wasted vectorize pass.
Inputs (9)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| background_mode | COMBO | 3 options: auto, white, black | |
| background_threshold | INT | 2400–255 | — |
| line_detection_method | COMBO | 3 options: edge, morphology, hybrid | |
| min_line_width | INT | 11–100 | — |
| max_line_width | INT | 501–500 | — |
| fill_handling | COMBO | 3 options: ignore, separate, include | |
| color_clusteringopt | BOOLEAN | false | — |
| num_colorsopt | INT | 52–20 | — |
Outputs (4)
| Name | Type | Description |
|---|---|---|
| line_mask | MASK | — |
| fill_mask | MASK | — |
| preview_image | IMAGE | — |
| color_info | STRING | — |