Nodes/face_mosaic/选择性图像马赛克(指定人物)
ComfyUI Node

选择性图像马赛克(指定人物)

Hide one person in a photo, leave the rest alone

By yzzky·Created 12 months ago·Updated 12 months ago· 0
选择性图像马赛克(指定人物)
  • image
  • processed_image
  • detection_info
◄reference_images►
◄recognition_backend▾►
◄similarity_threshold0.60►
◄mosaic_size20►
◄mosaic_type▾►
◄use_gputrue►

Group photo where one person asked not to be online? This is the node. The pack's other image nodes pixelate every face in the frame; this one takes reference photos of the person to hide, embeds them, and only mosaics faces that match - everyone else stays crisp. It's the still-image sibling of SelectiveFaceMosaicNode, listed as 选择性图像马赛克(指定人物) under YZZ_Face_Mosaic/Selective.

How it works

Same recognition machinery as the video version, applied once. You pick a recognition_backend - insightface (RetinaFace detection + buffalo_l embeddings, the heavyweight) or facenet (MTCNN + VGGFace2-trained InceptionResnetV1, lighter). For each path in reference_images (one per line) it extracts a face embedding, then it detects every face in your input image, embeds each, and compares with cosine similarity. Faces scoring at or above similarity_threshold get pixelate / blur / black_box; the rest pass through untouched.

The output is a standard IMAGE tensor, and - a nice touch for a recognition node - it also returns a detection_info STRING describing what it found and matched, so you can debug "why did it miss" without guessing.

Inputs

  • image - any IMAGE tensor.
  • reference_images - one file path per line. Give it the clearest face crop you have; two or three angles are meaningfully more robust than one.
  • recognition_backend - insightface for accuracy, facenet for a lighter footprint.
  • similarity_threshold - 0.3–0.9, default 0.6. Lower = masks more (including lookalikes); higher = stricter, risks missing the actual target in odd lighting.
  • mosaic_size, mosaic_type, use_gpu - the usual suspects.

Outputs: processed_image (IMAGE) and detection_info (STRING).

Installing it - the extra backend step

The pack itself is ComfyUI Manager → yzz_face_mosaic, or git clone https://github.com/yzzky/yzz_face_mosaic into custom_nodes + pip install -r requirements.txt, restart. But the recognition backend is not in requirements.txt - install one of:

pip install insightface onnxruntime-gpu    # insightface backend
# or
pip install facenet-pytorch                # facenet backend

First run downloads model weights (buffalo_l for insightface, VGGFace2 for facenet), so give it a minute and internet access.

Where it bites

Recognition quality is the whole game here. A reference photo that's small, blurry, or from a wildly different angle than the target in your image will lower your match scores - drop the threshold toward 0.5 if your person keeps escaping, raise it if strangers keep getting caught in the dragnet. And the quiet-failure warning applies here too: backend missing → no matches → image returned with nothing masked. If that happens, the console tells you exactly which package to install.

CategoryYZZ_Face_Mosaic/Selective

Inputs (7)

NameTypeDefaultDescription
imageIMAGE—
reference_imagesSTRING—
recognition_backendCOMBO2 options: insightface, facenet
similarity_thresholdFLOAT0.600.3–0.9—
mosaic_sizeINT205–100—
mosaic_typeCOMBO3 options: pixelate, blur, black_box
use_gpuBOOLEANtrue—

Outputs (2)

NameTypeDescription
processed_imageIMAGE—
detection_infoSTRING—