kubakub regions from sketch
Every closed shape in your drawing becomes a region — gaps and all
- drawing
- line
- matrix
- scope
- regions
- region_masks
- regions_json
- preview
- report
- closed_lines
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.
Inputs (10)
| Name | Type | Default | Description |
|---|---|---|---|
| drawing | IMAGE | From kubakub scan to line (or any line drawing on white). | |
| gap_px | INT | 240–500 | Largest gap between strokes that still closes a shape (pixels of the drawing). |
| line_threshold | FLOAT | 0.300.01–0.99 | How strong a stroke must be to count as a wall between shapes. |
| colour_names | BOOLEAN | true | Coloured marker dots name the shape they sit in (and are no wall). |
| outside | COMBO | keep | drop = shapes touching the edge of the paper are no regions (the sky around a drawn building). |
| min_region_area | INT | 4000–100000000 | Shapes smaller than this (pixels) - hatching, little marks - are merged or dropped. |
| merge_small_regions | BOOLEAN | true | On: small shapes join the neighbour with the longest border. Off: dropped. |
| lineopt | MASK | The line output of scan to line (better than the drawing alone). | |
| matrixopt | IMAGE | Your matrix: the preview background, and the size of the regions (a drawing of another size is fitted to it; same proportions only). | |
| scopeopt | MASK | Pixels outside this mask are never part of a region (the size of the matrix, or of the drawing without one). |
Outputs (6)
| Name | Type | Description |
|---|---|---|
| regions | KUBA_REGIONS | Label map + region table for the kubakub region nodes. |
| region_masks | MASK | One mask per region; batch index = region_id. |
| regions_json | STRING | The region table as text. |
| preview | IMAGE | Regions over the drawing (or the matrix), one colour per group. |
| report | STRING | Regions and groups found, gaps bridged, shapes named by colour, small shapes merged or dropped. |
| closed_lines | MASK | The 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. |