DOGMA v40 Multi-Instance Crops
DOGMA v40 Multi-Instance Crops
- image
- masks
- crops
- crop_masks
- stitch
- info
The v40 cropper is the "just work" version. Where DOGMAAdaptiveCropsV39 hands you max_groups, context_px and target_long_side as knobs, V40 takes four inputs and figures the numbers out from the category and kind itself. Whether that's a gift or a cage depends on how much you like tuning, but for a first pass it's the one I'd wire in.
What it takes, what it gives
Required: image, masks, category, kind. That's it - no reference_image, no sliders. Outputs: crops, crop_masks, stitch, info, all lists except info.
Two mechanisms are worth understanding because they're the reason this node exists at all. First, canonicalisation: the category string is scrubbed and then collapsed onto a fixed vocabulary - "sedan"/"automobile"/"vehicle" all become cars, "lorry" becomes trucks, "pedestrian"/"crowd" become people, "facade" becomes buildings, "asphalt"/"sidewalk" become road, and so on. That canonical name drives everything downstream: the family (vehicle / human / structure / vegetation / surface), the SAM prompt, the grouping budget, and the crop size.
Second, multi-instance grouping. Each SAM mask is broken into connected components, tiny ones dropped, components over 45% of the mask area rejected as background blobs, then overlapping detections deduplicated at IoU ≥ 0.68. The survivors are then clustered by bounding-box gap: up to 4 objects per crop within roughly 100-120px of each other, up to 8-10 crops per group set depending on the family. Then each cluster gets context padded (112px for people, 128px for everything else and vehicles) and resized so its long side lands at 1536.
Grouping four neighbouring cars into one crop is the cheap move, and this pack is honest about why: every crop is a Klein sampling pass, and the number of passes is what kills you. It's also where the classic detailer failure lives - one seed across several subjects converges them into near-clones. Grouping adjacent instances and giving the crop its own prompt is a partial answer; varying the seed per crop is the rest.
For STRUCTURE and SURFACE, the node unions the masks, takes the bounding box, adds 128px of ring, and if the region exceeds 1.15 × 1792 it lays down overlapping windows on a stride of ~0.78 × 1792 - capped at 6 windows for structure and 5 for surface. Macro crops at 1792, detail-injection behaviour, not regeneration.
The safe no-op
category="none", an empty mask, a mask whose coverage is under 0.01%, or a mask with no components all return a safe no-op: a centred 256px crop with a zero mask and a noop record, plus a info string like "road: no valid segmentation - safe no-op". Downstream Klein still runs, the stitch composites nothing, the graph survives. This pattern is why the v39/v40 family is nicer to leave running unattended than a hand-built detailer.
Install
cd ComfyUI/custom_nodes
git clone https://github.com/axior/ComfyUI-DOGMA-Nodes
Or Manager → DOGMA Nodes, restart after. pyproject.toml sets dependencies = [] and requirements.txt says "No external dependencies", so installation is a git clone and a restart - no Impact Pack-style dependency roulette. The hidden cost is compute: a v40 run is a Qwen3-VL pass to write the inventory, a grounded SAM for masks, and FLUX.2 Klein per crop. The GitHub README doesn't mention this node (it only documents WAN VACE and the sampler work), so read the node, not the repo landing page.
Common issues
All my crops are 1536px and my 8K source looks soft. By design: V40 hardcodes target=1536 for object crops. If you need 2048+, use V39, which exposes target_long_side.
Two cars got merged into one crop and the prompt only fixes one. That's the grouping heuristic doing its job with a mask that arrived merged. Feed V40 per-instance masks (component splitting only works if the mask actually has separate components).
Crops are misaligned relative to the masks. V40 scales mask coordinates from the mask resolution to the image resolution with independent x/y factors, so a mask at a wildly different aspect ratio will drift. Feed masks that match your image aspect; don't hand it a 512×512 preview mask for a 4:5 render.
A sector silently does nothing. Check info. If it says no-op, the category canonicalised to none or the mask was empty - the planner or the SAM stage is where you look, not here.
Inputs (4)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| masks | MASK | — | |
| category | STRING | — | |
| kind | STRING | — |
Outputs (4)
| Name | Type | Description |
|---|---|---|
| crops | IMAGE | — |
| crop_masks | MASK | — |
| stitch | DOGMA_STITCH | — |
| info | STRING | — |