arkennemasis Mask Refine (clean a video mask)
Turning a jittery segmentation mask into something you can composite
- masks
- masks
- report
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_largesthandles most, tunemin_area_pctif 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.
Inputs (9)
| Name | Type | Default | Description |
|---|---|---|---|
| masks | MASK | The raw masks, one per frame. | |
| threshold | FLOAT | 0.500.01–0.99 | Below this a pixel is background. A soft mask composited straight through shows a grey fringe. |
| keep_largest | BOOLEAN | true | Drop 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_holes | BOOLEAN | true | Close enclosed gaps. Turn OFF when a genuine hole through the subject must stay transparent. |
| grow | INT | 1-20–20 | Pixels to expand (+) or contract (-) the edge. Segmenters usually cut just inside the subject, so a small positive value recovers the hair line. |
| temporal_smooth | INT | 30–15 | Frames 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. |
| feather | INT | 20–40 | Softness of the final edge, in pixels. A hard edge reads as a sticker pasted on the background. |
| min_area_pctopt | FLOAT | 100–100 | A component this percentage of the largest is kept. 0 keeps every blob, 100 keeps strictly the largest. |
| invertopt | BOOLEAN | false | Flip the mask. Use when the segmenter returned the background rather than the subject. |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| masks | MASK | — |
| report | STRING | — |