Mask: Edge-Aware Refiner
Stop hand-fixing chipped SAM masks — let the image steer the edge
- mask
- guide
- refined_mask
Detector masks are chipped. SAM, YOLO, rembg, even a hand-painted mask - the boundary is always a few pixels off from where the actual edge lives, which is how you get those white halo rings around a subject after compositing. JHPixelProEdgeAwareMaskRefiner is the pack's cheap, fast answer: it takes your rough mask and a guide image, and snaps the mask's edge onto the image's structure. It's a guided filter (the He, Sun, Tang approach, which your OpenCV might know as guidedFilter), applied as a pure tensor operation.
The mental model is simple: instead of blurring the mask blindly, it filters in the direction of the guide image's edges. A rough mask edge over a strong edge in the photo (hairline, jacket seam, face silhouette) gets pulled toward that edge. Flat regions smooth out. The result is a mask that hugs the subject instead of hovering around it.
The inputs that matter
radius(default 8): the guided-filter neighborhood, in pixels. Bigger radius = the edge can travel farther to snap to image structure, but also more smoothing. Start at 8, nudge up if the mask still sits off-edge.eps(default 0.001): edge sensitivity. Lower = the filter respects image edges more aggressively; higher = it behaves more like a plain blur. This is the knob to reach for when edges come out too wobbly or too rigid.feather_sigma(default 0): optional Gaussian feather applied after the refine, in pixels. Handy if you know the downstream composite wants a soft edge anyway.
Everything else is plumbing. The output is a single refined_mask MASK in [0,1].
Where it fits
This is the fast cleanup stage - the pack's own docs frame it as "the fast cleanup step before heavier alpha-matte extraction or final edge smoothing." So the sensible pipeline is: SAM/rembg → Edge-Aware Refiner → (if you need true soft alpha) Alpha Matte Extractor. Or: refiner → composite. For most cutouts, the refiner alone kills the halo and you're done.
It also plays nicely with the pack's skin work. Refine a face mask against the portrait, then feed it into the Edge-Aware Skin Smoother as a region gate so smoothing only touches the face and stops at the jawline - that's exactly the "mask quality controls everything downstream" lesson from the inpainting world, applied in graph form.
Install
ComfyUI Manager → search ComfyUI-JH-PixelPro, or:
cd ComfyUI/custom_nodes
git clone https://github.com/jetthuangai/ComfyUI-JH-PixelPro.git
cd ComfyUI-JH-PixelPro
pip install -r requirements.txt
Restart ComfyUI and you'll find it under ComfyUI-JH-PixelPro/mask. The pack needs ComfyUI ≥ 0.43.x, Python ≥ 3.10, and pulls in kornia, mediapipe, opencv-python-headless, and scipy - PyTorch comes along with ComfyUI itself.
One thing worth knowing: the guide and mask need to be the same spatial size (the node raises if the guide's H×W doesn't match the mask), so if you're refining a mask against a downscaled image, keep them in sync. And remember this node is binary-leaning - if you feed it a soft alpha you'd like to preserve as-is, the guided filter will reshape it. Use it before you've committed to fine alpha, or just keep a copy of the original around. For a beginner this is one of those "wire it in, watch the halo disappear" wins - genuinely the node that makes SAM cutouts look finished.
Inputs (5)
| Name | Type | Default | Description |
|---|---|---|---|
| mask | MASK | — | |
| guide | IMAGE | — | |
| radius | INT | 81–32 | — |
| eps | FLOAT | 0.00100.000001–1 | — |
| feather_sigma | FLOAT | 0.00–64 | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| refined_mask | MASK | — |