Nodes/ComfyUI-Utility-Suite/Restore Tile SEGS Gaps
ComfyUI Node

Restore Tile SEGS Gaps

Put back the tiles your filter dropped through the floor

By tom-m-2020·Created about a month ago·Updated 7 days ago· 1
Restore Tile SEGS Gaps
  • segs
  • excluded_segs
  • segs
◄mode▾►
◄min_overlap_x128►
◄min_overlap_y128►

Tiled passes get faster by doing less work, and the standard way to do less work is to drop tiles that have nothing in them. This pack's Filter Tile SEGS does exactly that: it keeps only the tiles holding content in pixels nobody else covers and hands you the rest as excluded_segs. Then you paste the survivors together - and sometimes there's a seam. The tile you dropped was the only thing bridging two survivors that barely overlap each other, and now there's a strip of the image only one tile was ever going to reach.

Restore Tile SEGS Gaps is the repair step. Feed it the survivors and the excluded set, and it reconsiders excluded tiles that cover one of those gap strips.

How it works

It's geometry, not guesswork, and the sequence is worth following because it tells you what it needs from you:

  1. Both SEGS must describe the same source canvas, and the two sets must be disjoint - each tile is either kept or excluded, not both. Crop regions must be unique.
  2. It reconstructs the full source mask by laying all the tiles back down in their crop positions. Overlapping crops have to agree on the values they share, or it stops with an error rather than picking a winner.
  3. It groups the tiles into rows and columns by their spans and looks along each line. For every pair of surviving tiles that are adjacent in that line, it measures the actual overlap between them. If that's below min_overlap_x (along a row) or min_overlap_y (along a column), it computes the deficit band - the strip of pixels in the middle of the shortfall.
  4. It only bothers if that band actually contains paint in the reconstructed source mask. Restoring a tile over an empty strip would be work for nothing.
  5. Then it collects the excluded tiles sitting between those two survivors, pulls in their row or column neighbours as well, and re-runs the same partition test on that candidate set. Survivors of that second test get added back.
  6. Output is kept plus restored, sorted into geometry order (top to bottom, left to right).

Step 5 is the clever bit: the restored tile isn't just any excluded tile in the gap, it still has to pass the "am I the only one covering content here" test. So this loosens the filter slightly rather than undoing it.

Inputs and outputs

  • segs - the kept set, straight from Filter Tile SEGS.
  • excluded_segs - the second output of that same node. These two are a pair; feeding a mismatched or hand-edited pair is how you get the identity and duplicate checks throwing.
  • mode - mask or bbox, matching the mode you used in Filter Tile SEGS. mask tests the tile's actual mask pixels, bbox tests the area inside the tile's bbox. Keep the two consistent or you're re-adjudicating tiles on different grounds than the ones that dropped them.
  • min_overlap_x / min_overlap_y - default 128 each, and they're the threshold that defines "insufficient continuity". Set them to the minimum overlap you can actually blend across. Set both to 0 and the node does nothing at all: no gaps are ever detected, no candidates are collected, and you get your survivors back.

Output: segs.

When it's worth it

Honestly, this is a specialist node for a hand-rolled tiled pipeline: a canvas → MASK to Tile SEGS → Filter Tile SEGS → Restore Tile SEGS Gaps → paste/blend chain, with Reorder SEGS if you care about processing order. The reason to prefer this over simply not filtering is cost - you keep the speed win on the blank majority of tiles while repairing only the specific seams the filter created. If your canvas is small enough that filtering never saved you anything, skip the whole chain.

Install

Manager: search ComfyUI Utility Suite (publisher tom-m) → install → restart. Manual:

cd ComfyUI/custom_nodes
git clone https://github.com/tom-m-2020/ComfyUI-Utility-Suite

No models, no downloads; the pack's only requirement is opencv-python-headless, unused by this node. Written against ComfyUI's V3 node API, so keep ComfyUI reasonably current - an old build loads the folder and registers nothing.

Troubleshooting

"requires overlapping cropped masks to contain identical source-mask values." The tiles didn't all come from the same mask. This happens when SEGS from two different sources get merged before the filter, or when a crop was modified in between. It's a real inconsistency, not a fussy check: the node needs one coherent source to reason about the gap.

"cannot evaluate a connection region not fully represented by the input SEGS masks." A gap strip falls outside every tile you gave it - usually because the dropped tiles weren't included in excluded_segs, or the two sets have overlapping membership.

Nothing changed. Check min_overlap_x/min_overlap_y against the overlap your tiles actually have. If the survivors' real overlap already exceeds the threshold, no gap is ever flagged.

CategoryUtility Suite/SEGS

Inputs (5)

NameTypeDefaultDescription
segsSEGS—
excluded_segsSEGS—
modeCOMBO2 options: mask, bbox
min_overlap_xINT1280–32768—
min_overlap_yINT1280–32768—

Outputs (1)

NameTypeDescription
segsSEGS—