Nodes/kubakub nodes/kubakub regions from sketch
ComfyUI Node

kubakub regions from sketch

Every closed shape in your drawing becomes a region — gaps and all

By kubakubkub·Created about a month ago·Updated 2 days ago· 10
kubakub regions from sketch
  • drawing
  • line
  • matrix
  • scope
  • regions
  • region_masks
  • regions_json
  • preview
  • report
  • closed_lines
◄gap_px24►
◄line_threshold0.30►
◄colour_namestrue►
◄outsidekeep►
◄min_region_area400►
◄merge_small_regionstrue►

Hand-drawn strokes do not meet. That's the entire problem this node solves, and it's why you can't just feed a phone photo of a facade sketch into a normal line-drawing regulator and get usable regions out of it. The pen lifts, the line stops two millimetres short, and suddenly the "window" you drew is not a closed cell - it's a hole in the sky.

kubakub regions from sketch extends every stroke end to the nearest line within gap_px, closes the shapes, and then treats each closed shape as a region.

How it reads your drawing

drawing takes an IMAGE - the line output of kubakub scan to line is the intended source, because that's the node that straightens and cleans a phone photo of a sketch, but any line drawing on white works.

gap_px (24 by default) is the star input: the largest gap between strokes that still counts as closed. Too small and your drawing falls apart into one giant region; too large and separate windows merge into each other. You'll iterate on it once per drawing, then never think about it again. And you get a diagnostic for it - see closed_lines below.

line_threshold (0.3) is how strong a stroke must be to count as a wall. Raise it if pencil shading is being read as walls; lower it if your lines are faint.

colour_names is the fun one. Put a dot of coloured marker inside a shape and it names that shape: the region gets the colour as its name (red_1, red_2…) and as a tag. So a quick red dot on each window and [tag:red] in your region plan picks them all, without you naming anything by hand and without a single click in an annotation tool. Marker dots are not treated as walls, so they don't break the shape they're in.

Shapes drawn alike land in one group - which is the other half of the trick. Sketch the windows the same way, and they group themselves.

outside is keep or drop. Drop means shapes touching the edge of the paper aren't regions, which is what you want when you've drawn a building and the paper around it is one enormous "region". min_region_area and merge_small_regions handle hatching and little marks: 400 px by default, merging into the neighbour with the longest shared border rather than vanishing.

The output that tells you if it worked

regions (for the plan), region_masks, regions_json, preview (regions over the drawing or your matrix, one colour per group), and report - regions and groups found, gaps bridged, shapes named by colour, small shapes merged or dropped.

But the one to actually look at is closed_lines: the lines the shapes were cut with, your strokes plus the bridges over the gaps. White is wall. Where a shape closed you see a bridge you didn't draw; where a shape is still open you see the gap sitting there. That single output turns gap_px from a guess into a two-second read.

Connect matrix (optional) to set the region size and use it as the preview background - the drawing is fitted to it, same proportions only - and scope to bound where regions may be. line (optional) takes the MASK from scan to line, which is better than the drawing alone because it's already been thresholded and straightened.

Install

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

Manager → kubakub nodes, or comfy node install comfyui-kubanodes. ComfyUI 0.37.0+, OpenCV. No models. This is a genuinely light node - no Blender, no SAM, no video models. And the pack's workflow 05 is exactly this: a hand sketch rendered region by region, no files of yours needed.

Practical notes

Grouping is a property of the drawing, not the node. "Shapes drawn alike land in one group" means your sketch discipline shows up directly in how easy the region plan is to write. If every window is drawn with a different flourish, you'll be writing forty rules instead of one.

This is a great first project in the pack. Phase one of a real job is usually a conversation with a client about what should go where, and being able to sketch it on paper, photograph it, and get a promptable region atlas back out is a genuinely useful circuit. The regions you get are approximations of a building, but they're excellent placeholders - and you can swap in an Illustrator file or a cryptomatte later without rewriting the plan, because the plan only cares about names and tags.

Categorykubakub/2d/sketch

Inputs (10)

NameTypeDefaultDescription
drawingIMAGEFrom kubakub scan to line (or any line drawing on white).
gap_pxINT240–500Largest gap between strokes that still closes a shape (pixels of the drawing).
line_thresholdFLOAT0.300.01–0.99How strong a stroke must be to count as a wall between shapes.
colour_namesBOOLEANtrueColoured marker dots name the shape they sit in (and are no wall).
outsideCOMBOkeepdrop = shapes touching the edge of the paper are no regions (the sky around a drawn building).
min_region_areaINT4000–100000000Shapes smaller than this (pixels) - hatching, little marks - are merged or dropped.
merge_small_regionsBOOLEANtrueOn: small shapes join the neighbour with the longest border. Off: dropped.
lineoptMASKThe line output of scan to line (better than the drawing alone).
matrixoptIMAGEYour matrix: the preview background, and the size of the regions (a drawing of another size is fitted to it; same proportions only).
scopeoptMASKPixels outside this mask are never part of a region (the size of the matrix, or of the drawing without one).

Outputs (6)

NameTypeDescription
regionsKUBA_REGIONSLabel map + region table for the kubakub region nodes.
region_masksMASKOne mask per region; batch index = region_id.
regions_jsonSTRINGThe region table as text.
previewIMAGERegions over the drawing (or the matrix), one colour per group.
reportSTRINGRegions and groups found, gaps bridged, shapes named by colour, small shapes merged or dropped.
closed_linesMASKThe lines the shapes were cut with: your strokes plus the bridges over the gaps (white = wall). Shows where gap_px closed a shape, or still leaves one open.