Combine Masks to Instance (MIDI-3D)
Stitch up to seven binary masks into one instance mask (SAM-friendly)
- mask1
- mask2
- mask3
- mask4
- mask5
- mask6
- mask7
- instance_mask
If you're coming at MIDI-3D from a SAM or GroundingDINO workflow - one binary mask per object - this is the node that connects your world to the pack's. Combine Masks to Instance takes up to seven separate object masks and fuses them into the single labeled instance mask that MIDI-3D's preprocess step requires. RGB to Instance Mask handles the color-painted-mask crowd; this one is for people with per-object masks already in hand, which is exactly the SAM use case the source calls out.
How it works
- mask1 (required) - the first object mask, which becomes instance 1.
- mask2 … mask7 (optional) - more object masks, becoming instances 2 through 7 in order. Only wire in the ones you have; unconnected inputs are ignored.
The node thresholds each mask at 0.5, stamps it into the combined image with its label number, and outputs a single instance_mask MASK. Seven is a hard ceiling, by the way - this pack's model generates a handful of objects at once, so seven instances is plenty. If you genuinely have more, you're past what this node is designed for.
One behavior worth knowing: in overlapping regions, later masks overwrite earlier ones. If mask3 overlaps mask1, the overlap becomes instance 3. That's usually what you want - it's how you'd express "the mug sits in front of the table" as a mask - but if your objects overlap in confusing ways, order your inputs so the front object comes last.
When to reach for it
The classic setup is: SAM produces a mask per detected segment, you pick the segments you care about, and you want all of them in one labeled mask for MIDI-3D. Wire each chosen segment into its own input, run this node, and the combined mask flows into MIDI-3D Preprocess:
SAM masks → Combine Masks to Instance → MIDI-3D Preprocess → MIDI-3D Process
It also works as a general purpose "merge my masks" utility outside MIDI-3D - a labeled output like this is handy for any segmentation-dependent workflow, not just this pack. Don't overthink it.
The things that bite
- Misaligned masks. Every input must share the same dimensions. If your SAM masks are at different resolutions than the scene image, merge nodes or resize them first - otherwise the fused labels land in the wrong places and your 3D objects come out looking like the mask was drawn by a confident toddler.
- Binary vs. soft masks. The 0.5 threshold means soft-edged SAM masks get hard-cut. That's fine - the preprocess step expects hard labels - just don't expect feathering to survive.
- Later-wins overlaps. If an overlap turns out to be the background object (mask1 painted over by mask2 where the table should show through), reorder the inputs. The order you plug in literally decides what's on top.
Compared to the rest of the pack this one is trivial - a mask merger, no model involved, instant to run. It's also the most likely to silently misbehave if you feed it sloppy masks, because "sloppy" becomes "wrong instance labels" without a clear error. Check the combined output with a preview node once, and you'll catch most problems before they cost you a ten-minute diffusion run.
Inputs (7)
| Name | Type | Default | Description |
|---|---|---|---|
| mask1 | MASK | First object mask (becomes instance 1) | |
| mask2opt | MASK | Second object mask (becomes instance 2) | |
| mask3opt | MASK | Third object mask (becomes instance 3) | |
| mask4opt | MASK | Fourth object mask (becomes instance 4) | |
| mask5opt | MASK | Fifth object mask (becomes instance 5) | |
| mask6opt | MASK | Sixth object mask (becomes instance 6) | |
| mask7opt | MASK | Seventh object mask (becomes instance 7) |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| instance_mask | MASK | Combined instance segmentation mask |