Nodes/kubakub nodes/kubakub scan to line
ComfyUI Node

kubakub scan to line

Phone photo of a pencil sketch in, projector-ready line art out

By kubakubkub·Created about a month ago·Updated 2 days ago· 10
kubakub scan to line
  • photo
  • drawing
  • line
  • projection
  • found
  • corners
  • report
◄width0►
◄height0►
◄linepencil►
◄clean0.50►
◄boost1.00►
◄dots_in_linefalse►
◄corners►

Sometimes the fastest way to get a design onto a facade is to print the template, draw on it with a pencil, photograph it and let the computer clean up. That's the workflow this node exists for, and it's a lot more practical than it sounds: you can hand a printout to a client, they sketch, and ten seconds after you photograph it the drawing is on the matrix at the right size, with the paper, the lamp and the shadows gone.

What it does, mechanically

It's a deterministic image operation, not a model - no diffusion pass, no checkpoint. Four steps: find the paper in the photo (brightness-based), straighten it to the target size with a perspective warp, divide out the paper colour, the lamp's gradient and the grain, then split what's left into a line.

That "divide out" part is why this beats a simple threshold in Photoshop. A phone photo of a sketch is never evenly lit - one corner is in your shadow, the other is blown out by a window. The node normalises the illumination first, so a stroke on the dark side reads as strongly as a stroke on the bright side. Then pencil mode keeps the soft greys of the stroke and ink mode crushes everything to clean black and white.

The inputs that matter

photo is the picture(s). The paper needs to be brighter than whatever it's lying on, because that's how it finds it. Dark table, white paper: fine. White paper on a marble counter: you'll need corners.

width and height are the matrix size. Default 0 means "the paper's own size", which is fine for a quick look but wrong for a real graph - link these from project settings so the scan lands on the same matrix as your regions. Then draw on a print of the template and it lands exactly where it belongs. Also note that the regions-from-sketch node only accepts a drawing of the same aspect ratio as the matrix; it refuses others outright, so if that's your error message, you skipped this step.

line picks pencil or ink. clean (0.5 default, 1 = only strong lines) decides how much paper grain and faint scratch survives - crank it if you photographed on textured paper. boost (default 1) makes light pencil darker above 1, or keeps it delicate below 1, which is the knob you reach for when the drawing looked strong in person and grey on screen.

Two optional ones earn their place. corners takes tl tr br bl in photo pixels when the automatic paper search grabs the wrong quadrilateral - you normally get the right numbers from the node's own output and paste them back. dots_in_line controls whether coloured marker dots stay in the line and projection outputs; leave it off when you're using those dots to name regions.

Outputs and wiring

  • drawing - the drawing on white, coloured strokes kept. The one to preview and show people.
  • line - a MASK of line strength 0..1. Goes into kubakub regions from sketch to become closed shapes and regions, or into kubakub line overlay to lay your hand back on top of a render.
  • projection - white lines on black, ready to hand to a projector as-is.
  • found, corners, report - the debugging trio. found is the photo with the paper outline it used drawn on it, corners is the string you paste into the input to fix a bad detection, and report is one line per photo: how the paper was found, how big it was in the photo, what size it was straightened to, which corners were used.

That per-photo report matters when you're scanning a batch - a drawn animation, one photo per frame - because it lets you spot the single frame where the paper search grabbed the shadow instead of the sheet. The batch is processed frame by frame, so one bad frame means one bad frame, not a ruined sequence.

Install

It ships inside the pack; there's no extra model or dependency:

cd ComfyUI/custom_nodes && git clone https://github.com/kubakubkub/ComfyUI_KubaNodes
python -m pip install -r ComfyUI_KubaNodes/requirements.txt

Or search kubakub nodes in ComfyUI Manager. This node lives under 2d / sketch; if it's missing from your menu, check whether 2d/sketch or its parent group got switched off in kubakub.ini - the console line [Kub] kubakub.ini: ... off (N nodes hidden) is your confirmation.

What goes wrong

The usual failure is paper detection on a low-contrast surface, and the fix is always the same: read the corners out of the node and paste them in. Do that once per setup and the whole batch is stable.

The second is aspect ratio. Setting width/height to 0 gives you the paper's proportions, which will be a phone camera's idea of a rectangle, not your matrix's 16:9. Link the size from project settings before you wire the mask into the regions node and you avoid a confusing downstream error.

Worth knowing before you invest in the sketching workflow: the pack runs this chain on a built-in sample facade sketch photo, so template 05 sketch to render runs the whole pencil-to-projection path with no files of yours. Draw something rough, photograph it, and compare - that's the honest way to find out whether your drawing habits and clean / boost agree.

Categorykubakub/2d/sketch

Inputs (8)

NameTypeDefaultDescription
photoIMAGEPhoto(s) of the drawing; the paper should be brighter than the table.
widthINT00–16384Matrix width (link it from project settings); 0 = the paper's own size.
heightINT00–16384Matrix height; 0 = from the width and the paper's proportions.
lineCOMBOpencilpencil = keep the soft greys of the stroke; ink = clean black and white.
cleanFLOAT0.500–1How much paper grain and faint marks are removed (1 = only strong lines).
boostFLOAT1.000.2–4Makes light pencil darker (above 1) or keeps it delicate (below 1).
dots_in_lineoptBOOLEANfalseOff: coloured marker dots (names for regions from sketch) are left out of the line and projection outputs. On: they stay.
cornersoptSTRINGPaper corners in the photo (tl tr br bl, pixels) when the automatic search picks the wrong shape. Empty = automatic.

Outputs (6)

NameTypeDescription
drawingIMAGEThe drawing on white, coloured strokes kept.
lineMASKLine strength 0..1 (for regions from sketch and line overlay).
projectionIMAGEWhite lines on black: ready to project as they are.
foundIMAGEThe photo with the paper outline that was used.
cornersSTRINGThe corners used (copy them into 'corners' to fix them).
reportSTRINGOne line per photo: how the paper was found, its size in the photo (pixels), the size it was straightened to and the corners used.