ComfyUI Node

Color Region Finder

Every fillable region in your line art, labeled and ready for a palette

By l2dnjsrud·Created 3 months ago·Updated 3 months ago· 0
Color Region Finder
  • image
  • region_preview
  • regions_json
threshold180
min_area32
max_regions128
ignore_border_regionstrue

Once your line art is clean and its gaps are closed, the next question is: which enclosed areas are actually fillable, and which one is "hair" versus "skin" versus "background"? Color Region Finder answers that. It takes closed line art, finds every connected white region the lines enclose, and hands you two things: a colored preview where each region gets its own label color, and a JSON dump of metadata for every region. This is the first concrete step toward OpenToonz-style indexed color editing - the whole reason this pack exists is to bring that old studio-workflow idea to modern AI colorization, where the region map becomes structured guidance for Qwen Image Edit, MangaNinja, or a reference-colorization pass instead of just vibes.

How it works

It's a connected-component labeling problem, solved with OpenCV. The node binarizes the input the same way its sibling Line Gap Closer does (pixels darker than threshold are line), then inverts it so fillable areas become foreground, and runs 4-connected component analysis. Each blob is a candidate fill region. Candidates below min_area are dropped, and by default any region touching the image border is dropped too - because a region touching the edge isn't actually enclosed by line art, it's open to the void. The survivors get sorted by area and assigned sequential style IDs, capped at max_regions. The preview just cycles those labels through a 10-color palette and draws the line art back on top in black.

Inputs that matter

  • threshold (default 180) - line definition. Keep it consistent with whatever you fed Line Gap Closer, so both nodes agree on what counts as a boundary.
  • min_area (default 32) - noise gate. Raise it when you get a confetti storm of tiny fragments; lower it to 8–24 when eyes or small accessories are vanishing.
  • max_regions (default 128) - the cap. If every image hits exactly 128, your input is too complex or too open; crop tighter.
  • ignore_border_regions (default on) - drop regions touching the image edge. Leave it on for panel crops; flip it off only if you're debugging page layouts.

Outputs

region_preview is the visual: colored labels with black line art overlaid, so you can see at a glance whether the segmentation matches your intent. regions_json is the payload that matters if you're scripting - each region gets an id, bbox [x, y, w, h], area, centroid, and a style_id you can treat as a palette index. That's the bridge to per-region color assignment, which is exactly what an OpenToonz-style pipeline wants from it.

Installing it

ComfyUI Manager → search comfyui-opentoonz-line-tools, or clone:

cd ComfyUI/custom_nodes
git clone https://github.com/l2dnjsrud/ComfyUI-OpenToonzLineTools.git

Restart and it lands under manga/opentoonz-line-tools. Dependencies are just numpy, opencv-python, and Pillow; no torch install, no model files, CPU-only.

Where people get burned

Same rule as its sibling: panel crops, not full pages. A full page has hundreds of open regions and border-touching blobs, and the max_regions cap will quietly truncate your map. The most common realistic failure is the threshold mismatch - if this node and Line Gap Closer disagree on what's a line, you'll get regions that should be separate bleeding together. And a note on expectations: this is a young, tiny research pack with basically zero community usage, so the palette preview is a sanity check, not a finished segmenter - for real segmentation quality you'd be reaching for a ControlNet aux lineart model or a vision model, but for cheap, structured, deterministic region metadata on a single panel, this is hard to beat.

Categorymanga/opentoonz-line-tools

Inputs (5)

NameTypeDefaultDescription
imageIMAGE
thresholdINT1800–255
min_areaINT321–100000
max_regionsINT1281–4096
ignore_border_regionsBOOLEANtrue

Outputs (2)

NameTypeDescription
region_previewIMAGE
regions_jsonSTRING