Nodes/ComfyUI_SVFR/SVFR_img2mask
ComfyUI Node

SVFR_img2mask

The tiny helper that turns your inpainting mask into one SVFR will actually accept

By smthemex·Created 2 years ago·Updated 2 months ago· 104
SVFR_img2mask
  • image
  • mask
threshold0
center_cropfalse
width512
height512

If you want SVFR to repair a damaged face video - scratching out scratches, watermarks, or corrupted regions - you run the sampler in inpainting (or bfr_color_inpaint) mode, and that mode demands a mask input. This node exists for exactly one job: take an image (typically a black-and-white mask you drew or generated) and hand SVFR_Sampler a MASK tensor it will actually accept. It's a two-minute helper, not a star, but it sits in the middle of every inpaint workflow for this pack, so it's worth knowing what it does before you wire up something fancier.

How it works

The logic is refreshingly simple and it's all about not making you think about polarity. The node converts your image to grayscale and counts how many pixels are dark versus bright:

  • If black dominates, it treats white as the "affected" region and outputs 255 for every pixel above your threshold, black elsewhere.
  • If white dominates, it flips it - pixels above the threshold become 0, everything else 255.

In other words, it auto-inverts the mask so the region you painted ends up as white regardless of whether you painted it in black on white or white on black. That "this mask is the thing I want fixed" convention is exactly what the sampler's inpainting path expects, because SVFR paints the masked-out area (the code literally sets the masked pixels to pure white before feeding frames to the UNet).

threshold (0–254, default 0) is the sensitivity cut: any pixel strictly above it counts as foreground. Default 0 treats everything except pure black as the region - good for clean black-on-white masks, fiddly if your mask has gray edges.

The inputs that matter

Three of the five are worth touching:

  • image - the mask image. Any grayscale or RGB image works; it gets squashed to one channel.
  • threshold - the cut point. Leave at 0 for clean binary masks.
  • center_crop + width/height - with center_crop on, it resizes the image to your width×height first (nearest-neighbor, center crop). Off by default, which matters if your mask resolution doesn't match the video frames you're restoring.

Output is a single mask (MASK) that plugs straight into SVFR_Sampler's optional mask input.

Install & gotchas

No separate install - it ships in the ComfyUI_SVFR pack alongside the model loader and sampler:

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

Or grab the pack via ComfyUI Manager ("ComfyUI_SVFR") and restart. The one real trap here is not a this-node problem: if you forget to feed the sampler a mask and let ComfyUI's placeholder 64×64 mask flow through instead, the sampler explicitly rejects it ("input mask is not a useful, looks like a default comfyUI mask"). That's exactly what this node is for - route your painted mask through it and the error goes away. Also note the sampler rejects any input video under 8 frames, so don't test your inpaint mask on a 3-frame clip and blame the mask.

CategorySVFR

Inputs (5)

NameTypeDefaultDescription
imageIMAGE
thresholdINT00–254
center_cropBOOLEANfalse
widthINT512128–2048
heightINT512128–2048

Outputs (1)

NameTypeDescription
maskMASK