Nodes/DOGMA Nodes/DOGMA Merge SAM + Audit v31 — Missed Defect Recovery
ComfyUI Node

DOGMA Merge SAM + Audit v31 — Missed Defect Recovery

When SAM misses the broken part, let the audit box rescue it

By axior·Created 4 months ago·Updated 3 days ago· 1
DOGMA Merge SAM + Audit v31 — Missed Defect Recovery
  • sam_masks
  • audit_masks
  • merged_masks
  • info
expand_px22

Two maskers, two different strengths, one node that merges them without letting either win. DOGMAMergeSamAuditV31 takes instance masks from a segmentation pass (sam_masks) and boxes from a defect audit (audit_masks) and returns a single stack with both problems handled.

The two failure modes it's built around

Segmentation is good at objects and blind to defects. Ask it for "cars" on a street scene and it will find you every car, cleanly, with proper silhouettes - including the one whose body panel has fused into the wheel arch. It sees a car. It doesn't see that the car is malformed.

A defect audit is good at defects and hopeless at objects. A vision model looking for things wrong in the frame will box the fused wheel arch, the melted shopfront, the three-legged dog. What it returns is rectangles. A rectangle around a car is not a car mask - trace it and you've selected half the road too.

So: segmentation makes the shape, the audit makes the location, and this node resolves the relationship between them.

What the merge actually does

SAM stays primary. The incoming audit boxes are resized to the SAM masks' resolution (nearest-neighbour, so no soft edges creep in) and SAM masks with essentially nothing in them - fewer than about four pixels above 0.5 - get dropped. The survivors get unioned.

Then, for each audit box with real area:

  • If the box overlaps SAM's union (even by a couple of percent), the node does not paste the box in. It takes the intersection of the SAM mask and the box as a seed, dilates that seed by expand_px pixels, and then caps the growth at a small dilation of the box itself. The result is the SAM-supported region grown into the interaction area the audit flagged - so you get the defect region corrected while the selection stays shaped like the actual object, not like a rectangle. Repeat for every overlapping box; each one contributes a separate mask.
  • If the box doesn't overlap SAM at all, the whole box survives as a fallback mask. This is the case where the segmentation model missed the object entirely - no car to find, because what's there is no longer car-shaped enough to recognise. The box is all you've got, and a roughly-right region that gets repaired beats a precise nothing.

The info string counts all three populations: SAM instances, overlap expansions, Qwen-only fallbacks, and the total mask stack size. If the fallback count is high, your segmentation is under-detecting and you should be looking at the SAM prompt or threshold rather than at this node.

The one dial

expand_px - default 22, range 0 to 96 in steps of 2. It's how far past the SAM boundary the repair is allowed to grow into the flagged interaction area. Zero means the box only ever restricts the mask, never grows it. Up around 40–60 you'll start wrapping the neighbours of whatever you're fixing, which is useful for a defect that spans two touching objects and ruinous for anything else.

Outputs are merged_masks (a single stacked MASK, instances concatenated along the batch dimension) and info. Feed the stack into your clustering/crop node.

Install

ComfyUI Manager → search DOGMA Nodes, or:

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

Restart. No pip dependencies and no model files - it's tensor arithmetic over masks you already have.

Where it bites

The overlap test is coarse - two percent of a box is a low bar - so a large box that clips the corner of a big SAM region will trigger the expansion path and add a mask that's mostly just the overlapping sliver. On a crop of a busy frame with generous audit boxes, expect the stack to grow and expect some entries to be near-duplicates of what SAM already gave you. Deduplicate upstream if that bothers you, or tighten the audit boxes before they get here.

Second, nothing here is semantic. The node can't tell a genuine defect box from a vision model hallucinating one; a bad audit box landing on top of a good SAM mask will still enlarge that mask. That's the argument for an audit-of-the-audit in the graph, which is exactly what the mask audit sheet and gate in this pack are for.

Third, the fallback boxes are rectangles by definition. If a region reaches the crop stage as a rectangle, your repair will have rectangular tendencies - the pack's stitch feathering does what it can, but a fallback mask is always going to be the weakest link in an otherwise mask-shaped pipeline.

CategoryDOGMA/Semantic Detailer

Inputs (3)

NameTypeDefaultDescription
sam_masksMASK
audit_masksMASK
expand_pxINT220–96

Outputs (2)

NameTypeDescription
merged_masksMASK
infoSTRING