DOGMA Local - Zone manuali o automatiche
Paint zones by hand, or let SAM find them, without OCR
- image
- mask
- sam_model
- sam_clip
- regions
- report
Most of the DOGMA pack assumes a machine decides where to work and you approve the list. This node is the other mode: you paint. Scribble over the broken sign, the damaged lettering, the surface you want redone, and the node splits your scribble into separate zones, expands each one by a configurable margin, and hands back a job per zone. Or you flip it to automatic and let a promptable segmenter propose the zones instead.
The point of the split is that the two halves of the problem have different failure modes. Painting is precise but tedious; detection scales but misidentifies things. Having both behind one switch means you can use detection to get 90% of the way and then paint over the two it missed.
How it works
In Manuale - the default - the node validates the mask you painted, then labels its connected components with 8-way connectivity. Each component becomes one zone. There is a hard cap of 128 zones; go over it and the node refuses and tells you to clean up isolated dots in the MaskEditor, without dropping anything behind your back. Each zone is then expanded by mask_expand_px in native pixels of the original photo, before cropping, and the zones are kept separate - expansion does not merge two neighbours into one job.
If you turn on refine_manual_masks, each brush stroke is treated as a hint rather than a contour: SAM is asked to propose the actual boundary of the thing you scribbled over, before expansion and feathering. The node keeps both versions and lets you choose per zone between Originale and Raffinata in the review popup. That is the feature to reach for when your hand is imprecise but your intent is clear.
In Automatico the node runs a SAM search instead: nine fixed queries - the sign-and-lettering vocabulary - across a set of overlapping windows of the photo, whose count depends on auto_detail. Dettagliata searches more views and finds smaller things; Rapida is cheaper. auto_threshold (0.25) and auto_max_regions (128) bound the results, and geometry guards throw out masks that are tiny or sprawling. Note the report's own line: no OCR. Nothing here reads text; it finds graphic-bearing surfaces.
Inputs and outputs
Required: image (one image, not a batch), mask (your painting - validated, alignment-checked, and refused if empty), context_px (48, the surrounding photo carried into each crop), render_side (2048, the long side of the crop used at render time), project_context (a long default art-direction string: Milan in the 1970s, match exposure, haze, grain, do not invent brands or QR codes), and rerun (bump to force a fresh run).
Optional: mask_expand_px (8), selection_mode (Manuale/Automatico), auto_detail (Dettagliata/Rapida), auto_threshold, auto_max_regions, refine_manual_masks, plus the lazy sam_model and sam_clip.
Outputs: regions (DOGMA_LOCAL_JOBS126) and report (STRING). The regions bundle goes into the pack's Local review node - where you write or generate a prompt per zone - and then into DOGMALocalRenderV126.
Install
cd ComfyUI/custom_nodes
git clone https://github.com/axior/ComfyUI-DOGMA-Nodes
Or ComfyUI Manager → DOGMA Nodes, then restart. scipy>=1.10 is the only declared pip dependency. Automatic mode and manual refinement both need a SAM checkpoint as MODEL plus its CLIP; plain manual mode needs neither, which is a nice property when you just want to paint a few zones.
Where people get burned
An empty mask. The node raises with a clear message rather than producing a no-op render. If you get it, save the mask from the MaskEditor on the same image the node is loading.
Too many zones. A mask full of stray dots after a slider drag can exceed 128 components. Clean them; the node will not quietly drop the extras.
Expecting automatic mode to read the sign. It finds surfaces that look graphic-bearing and gives you a crop. What goes on that surface is your prompt, or the review popup's business - not this node's.
Inputs (14)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| mask | MASK | — | |
| context_px | INT | 4816–512 | — |
| render_side | INT | 2048512–2048 | — |
| project_context | STRING | Milan, Italy, 1970s. Preserve the photograph and its physical objects. Use period-appropriate Italian graphics when requested. Match existing exposure, light direction, fog, material, wear, focus, grain and perspective. A painted surface is non-emissive; do not add glow unless explicitly requested. Do not invent modern brands, websites, QR codes or euro prices. | — |
| rerun | INT | 00–999999 | — |
| mask_expand_pxopt | INT | 80–128 | Espande ogni zona in pixel della foto originale, prima del ritaglio. Le zone restano separate. |
| selection_modeopt | COMBO | Manuale | 2 options: Manuale, Automatico |
| auto_detailopt | COMBO | Dettagliata | 2 options: Dettagliata, Rapida |
| auto_thresholdopt | FLOAT | 0.250.05–0.95 | — |
| auto_max_regionsopt | INT | 1281–128 | — |
| refine_manual_masksopt | BOOLEAN | false | Manuale: usa pennellate separate come indizi, SAM propone il contorno prima di espansione e sfumatura. Off usa il disegno originale. |
| sam_modelopt | MODEL | — | |
| sam_clipopt | CLIP | — |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| regions | DOGMA_LOCAL_JOBS126 | — |
| report | STRING | — |