Nodes/ComfyUI_BadgerTools/FindThickLinesFromCanny-badger
ComfyUI Node

FindThickLinesFromCanny-badger

Reconnect broken edge lines — despite the name, it doesn't run Canny itself

By AbyssBadger0·Created 3 years ago·Updated 2 years ago· 8
FindThickLinesFromCanny-badger
  • image
  • IMAGE
low_threshold0.010
high_threshold0.020

The name is a lie, and it's worth knowing before you wire it up: FindThickLinesFromCanny-badger does not run a Canny edge detector. What it does is take an already-edged image - the dotted, dashed, broken output you get from a Canny preprocessor - and knit the fragments back into continuous thick lines, keeping only the single largest connected stroke. It's a line-repair node for lineart and sketch conditioning, and the "Canny" in the name is really just "the kind of image I'm feeding you."

Why would you want this? ControlNet lineart and Canny conditioning work better when the control image is a clean, continuous outline. A real-world edge map is full of gaps where the detector lost the trail, and those gaps read as "the line ends here" to the model. This node bridges the gaps - draws a straight white line between white pixels that are close enough to be the same stroke - then keeps the biggest connected component so you get one confident contour instead of forty fragments.

How it works

Under the hood it scans the image in four directions (horizontal, vertical, and both diagonals). Whenever it finds two white pixels separated by a gap that's between the two thresholds, it fills the gap with a line. Then a flood-fill finds the largest connected white region and keeps only that.

The two FLOAT inputs, low_threshold and high_threshold, are the gap-size window in fractions of image width - the code multiplies them by the image width to get pixel counts. So a gap of 15 pixels on a 512-wide image needs thresholds around 0.02–0.05, and the same numbers mean very different things at 2048px wide.

Inputs and outputs

  • image - an IMAGE, expected to be white lines on black (a Canny or lineart preprocessor output).
  • low_threshold (FLOAT, default 0.01) - gaps shorter than this are ignored; it won't connect the noise speckles.
  • high_threshold (FLOAT, default 0.02) - gaps longer than this are left broken; it won't bridge across the table, just across the fracture.

One output: an IMAGE, black background with the repaired largest line in white. It's effectively a single-stroke line mask - a decent starting point for a ControlNet condition or a mask for lineart-based inpainting.

Installing it

In ComfyUI_BadgerTools: ComfyUI Manager → search "BadgerTools" → install, or

cd ComfyUI/custom_nodes
git clone https://github.com/AbyssYuan0/ComfyUI_BadgerTools

Restart afterwards. No model downloads. Heavy requirements.txt imports at startup regardless of which node you actually use - normal for this pack.

Gotchas

  • Feed it an edge map, not a photo. It looks for exact 255-white pixels. A normal photo has almost none of those, and you'll get a black image back.
  • Thresholds are width-relative. The same pair of values behaves differently at different resolutions. If your lines connect everything into one blob, raise low_threshold; if nothing connects, raise high_threshold.
  • You get one line, not all of them. "Largest connected component" is a filter, not a cosmetic. If you need the whole sketch, this node isn't it.

There's no community consensus to cite for tuning - this is a niche personal-pack utility with a thin README. Budget ten minutes of threshold fiddling on your first real image; after that it's a one-shot node in the lineart pipeline.

Categorybadger

Inputs (3)

NameTypeDefaultDescription
imageIMAGE
low_thresholdFLOAT0.0100–1
high_thresholdFLOAT0.0200–1

Outputs (1)

NameTypeDescription
IMAGEIMAGE