Nodes/DOGMA Nodes/DOGMA v43 Region-Aware Crops
ComfyUI Node

DOGMA v43 Region-Aware Crops

Object, structure and surface get different rules

By axior·Created 4 months ago·Updated 3 days ago· 1
DOGMA v43 Region-Aware Crops
  • image
  • masks
  • crops
  • crop_masks
  • stitch
  • info
category
kind

The object-crop nodes treat every mask the same way: find the instance, group nearby instances, cut. That breaks the moment your inventory includes a building or sky. You don't want "the three largest façade instances grouped within 120px" - you want the connected region, whole, once.

DOGMARegionCropsV43 is the version that fixes that, by making the kind input do real work. It's a string that comes from the scene inventory alongside the category, and it accepts OBJECT, STRUCTURE or SURFACE. Pick wrong and the node doesn't error - it just hands you crops that are the wrong shape, which is much harder to debug.

Three behaviours, one node

OBJECT - explode every disconnected component of every mask into its own detection (threshold 0.26, flood-fill working at a downsampled 720px ceiling for speed), convert boxes to image coordinates, deduplicate at ≥0.72 IoU, then greedy-group within a per-category gap and rebuild each group's mask. The caps are category-specific and much more generous than the older object nodes: cars, buses and trucks get up to 4 instances per crop, 20 groups, a 140px gap, 128px context and a 1664px model long side; people get 4/16/110/112/1536; anything else 3/12/120/128/1664. Twenty groups is a lot of sampler calls - that's the "high-recall, this frame has a whole street in it" setting.

STRUCTURE - takes the union of the mask stack, finds real connected regions at threshold 0.24, keeps the four largest, and crops each with 144px of context, resized so the long side is at most 2048. No grouping, no dedup, no grid. The docstring's own emphasis: "true connected regions only, NEVER grids."

SURFACE - same as STRUCTURE but tighter: two largest regions, 112px context, threshold 0.24. Surface is for the big soft areas - road, sky, water - where two crops is plenty and more context just drags more scene into each pass.

For STRUCTURE and SURFACE the crop_masks output is the resized whole union mask rather than per-component masks, so the pass sees the full region. For OBJECT it's the group's local mask, unioned across its members.

Inputs and outputs

image, masks, category and kind in; crops (IMAGE list), crop_masks (MASK list), stitch (list), info out. The category is canonicalised first - free text like "1970s Italian cars" gets mapped to the cars family by keyword, so the caps and prompts line up - and if it resolves to none, or the mask stack is empty, you get a centred 256px crop flagged noop: True and an info line saying "no valid SAM region - safe no-op".

stitch here carries x, y, width, height, noop and kind per crop, and kind is the reason the matching stitch node can pick a different blend for a road than for a car.

Install

ComfyUI Manager → search DOGMA Nodes, or:

cd ComfyUI/custom_nodes
git clone https://github.com/axior/ComfyUI-DOGMA-Nodes
# restart ComfyUI

Nothing to pip install; masks and interpolation only. The README documents the WAN VACE prep and sampler nodes and says nothing about the v43 family, so the info string is your only runtime feedback.

Gotchas

kind is a plain string with no validation. "object" becomes OBJECT fine, but a typo falls through to the OBJECT branch and you'll spend an hour wondering why your sky got 20 crops. The inventory node upstream supplies it; if you're hand-wiring this graph, double-check the values.

Connected components are found on a downsampled copy. The flood fill works at a maximum dimension of 720 pixels and scales boxes back up, so two objects that are 3px apart in a 4K frame may merge or split differently than you'd expect. That's a speed trade the author took deliberately; it's also why tiny instances can be missed.

Only the first image of a batch is used (image[:1]). Per-frame loops in video pipelines, not batches.

CategoryDOGMA/v43

Inputs (4)

NameTypeDefaultDescription
imageIMAGE
masksMASK
categorySTRING
kindSTRING

Outputs (4)

NameTypeDescription
cropsIMAGE
crop_masksMASK
stitchDOGMA_STITCH
infoSTRING