Nodes/arkennemasis Nodes/arkennemasis Mask Refine (clean a video mask)
ComfyUI Node

arkennemasis Mask Refine (clean a video mask)

Turning a jittery segmentation mask into something you can composite

By Hishamahmer·Created about a month ago·Updated a day ago· 6
arkennemasis Mask Refine (clean a video mask)
  • masks
  • masks
  • report
threshold0.50
keep_largesttrue
fill_holestrue
grow1
temporal_smooth3
feather2
min_area_pct10
invertfalse

A segmentation model gives you a mask that's almost right, and "almost" is exactly what you can't composite with. Per-frame segmentation is right frame by frame and jittery as a video - the edge boils, a stray blob pops in for two frames, the hairline gets eaten. ArkMaskRefine is the cleanup pass that turns raw segmentation into a mask you can actually cut a subject out with.

The pack's own framing is the best summary: a segmenter is right frame by frame and jittery as a video. Refine it first, composite second. If you're building the avatar pipeline - a presenter cut out of a generated clip and stood in front of an article screenshot - this is the node between the segmenter and the overlay.

How it works

It takes your masks (one per frame) and runs them through a pipeline, in order:

  • threshold (0.5) - below this a pixel is background. A soft mask composited straight through shows a grey fringe; thresholding makes it binary.
  • keep_largest - drops blobs that aren't the subject. min_area_pct (10) sets how big a component must be relative to the largest to survive, so a limb split off by an occluder doesn't vanish - it's large enough to keep.
  • fill_holes - closes enclosed gaps. Turn it off when a genuine hole through the subject must stay transparent.
  • grow (1) - expands or contracts the edge by pixels. Segmenters usually cut just inside the subject, so a small positive value recovers the hair line.
  • temporal_smooth (3) - averages the mask over N frames. This is the setting that stops the edge boiling, and it's the reason the node exists at all. Keep it small; a fast gesture smears.
  • feather (2) - softens the final edge. A hard edge reads as a sticker pasted on the background.

There's also invert for the day a segmenter returns the background instead of the subject, and the report output tells you what it did per frame.

Installing

cd ComfyUI/custom_nodes
git clone https://github.com/Hishamahmer/comfyui-arkennemasis
pip install replicate httpx

Restart ComfyUI (ComfyUI Manager finds it under arkennemasis). It's pure tensor math on your existing masks - no model downloads, no keys.

Troubleshooting

  • Edge boils frame to frame: raise temporal_smooth. If it smears a moving arm, lower it - there's a real trade here, and 3–5 is usually the sweet spot.
  • Grey fringe around the subject: your mask was soft. Threshold it; that's the setting's job.
  • Hair looks cut off: raise grow. Segmenters habitually cut just inside the subject.
  • Floating specks and ghost blobs: keep_largest handles most, tune min_area_pct if a real part keeps disappearing.
  • Then feed the result into ArkOverlaySubject, which composites it. Refine before overlay - that's the intended order, and the overlay's tooltip says the same thing.
Categoryarkennemasis/Utility

Inputs (9)

NameTypeDefaultDescription
masksMASKThe raw masks, one per frame.
thresholdFLOAT0.500.01–0.99Below this a pixel is background. A soft mask composited straight through shows a grey fringe.
keep_largestBOOLEANtrueDrop blobs that are not part of the subject. Parts comparable in size to the biggest are kept, so a limb split off by an occluder does not vanish.
fill_holesBOOLEANtrueClose enclosed gaps. Turn OFF when a genuine hole through the subject must stay transparent.
growINT1-20–20Pixels to expand (+) or contract (-) the edge. Segmenters usually cut just inside the subject, so a small positive value recovers the hair line.
temporal_smoothINT30–15Frames to average the mask over. This is the setting that stops the edge boiling. 0 disables it; keep it small or a fast gesture smears.
featherINT20–40Softness of the final edge, in pixels. A hard edge reads as a sticker pasted on the background.
min_area_pctoptFLOAT100–100A component this percentage of the largest is kept. 0 keeps every blob, 100 keeps strictly the largest.
invertoptBOOLEANfalseFlip the mask. Use when the segmenter returned the background rather than the subject.

Outputs (2)

NameTypeDescription
masksMASK
reportSTRING