Skip to content

Repository files navigation

ComfyUI AutoMask Nodes thumbnail

ComfyUI-AutoMask

Custom nodes for ComfyUI that automatically refine and threshold masks — no manual trial-and-error with black/white points or fixed cutoff values.

Nodes

Mask Refine

mask refine node sample

BiRefNet

close up mask and image

BiRefNet -> Mask Threshold = 0.01 -> Mask Refine

close up refine mask and image

Refines a rough mask into a soft alpha matte using closed-form matting (pymatting), guided by the source image.

This node is a simplified implementation based on the Image Matting node from ComfyUI-Image-Filters by spacepxl, with preblur kept as the only exposed setting.

  • Inputs
    • imageIMAGE, the source image the mask was drawn on
    • maskMASK, the rough/binary mask to refine
    • preblurINT (default 10), Gaussian blur radius applied to the mask before it's converted into a trimap. Higher values soften hard mask edges before matting; 0 disables preblurring.
  • Output: MASK — a refined, soft alpha matte

Use this after any rough segmentation (SAM 3.1, BiRefNet, manual paint, threshold, etc.) to get cleaner edges, especially around hair, fur, or semi-transparent regions.

Auto Mask Threshold

auto mask threshold sample

Analyzes a soft mask's value histogram and automatically finds meaningful threshold boundaries (valleys between peaks) instead of requiring a manually chosen cutoff.

  • Inputs
    • maskMASK, a soft (non-binary) mask, e.g. the output of Auto Mask Refine
    • thresholdINT (default 5, range 18), selects the n-th detected boundary (ascending) for the single-mask output
  • Outputs
    • mask_batch (x8)MASK, a batch of up to 8 binary masks, one per detected boundary
    • maskMASK, the single binary mask selected by threshold
    • histogramIMAGE, a rendered histogram showing the detected peaks/valleys and which one was selected (also shown in the node preview)

Internally the node finds up to 5 valleys between histogram peaks plus up to 3 minor minima inside the largest peak, giving up to 8 candidate thresholds to choose from — useful for quickly comparing where different cutoffs land without re-running the graph.

Installation

Via ComfyUI Manager (recommended)

Search for "easygoing" in Nodes Manager and install.

comfyui extension search easygoing

Manual

After enabling the ComfyUI Python virtual environment:

cd ComfyUI/custom_nodes
git clone https://github.com/easygoing0114/ComfyUI-AutoMask.git
cd ComfyUI-AutoMask
pip install -r requirements.txt

Requirements

  • opencv-python
  • pymatting

Credits

License

About

Automatic mask refinement and histogram-based multi-threshold nodes for ComfyUI by easygoing0114

Topics

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages