Nodes/ComfyUI-ZML-Image/ZML_遮罩打码
ComfyUI Node

ZML_遮罩打码

Mask-based censoring with mosaic or image replacement — your own mask, your rules

By zml-w·Created about a year ago·Updated 2 months ago· 218
ZML_遮罩打码
  • 原始图像
  • 遮罩
  • 覆盖图
  • 处理后图像
  • 处理后遮罩
覆盖模式
拉伸图像false
马赛克数量5
遮罩缩放系数1.00
遮罩膨胀0

The ZML pack has an auto-censor node that runs YOLO to find faces or "sensitive" areas and blur them. This is the manual companion: you bring your own mask - from a face-detection node, an inpainting mask, whatever - and the node blurs or replaces exactly those regions. Where the auto node decides what to cover, this one lets you decide, which makes it the one you reach for when YOLO's idea of "what needs censoring" disagrees with yours.

How it works

It's OpenCV doing the heavy lifting. The node takes your mask, finds every connected contour in it, and processes each region independently - that per-region loop is the important bit, because it means a mask with ten blobs gets ten clean mosaic patches instead of one giant blurred smear. For each contour it:

  1. optionally 遮罩膨胀 (dilates) and 遮罩缩放系数 (scales) the region - inflating the mask is how you make sure nothing peeks out at the edges;
  2. applies the overlay in one of two 覆盖模式: paste an image (from the optional 覆盖图 input) stretched to fit the region, or drop a 马赛克数量-pixel mosaic block on it.

If 拉伸图像 is on, the replacement image is stretched to the region's bounding box; leave it off and the image keeps its own aspect ratio. You get back both the processed image and a processed mask reflecting exactly what ended up covered, so you can chain further edits that only apply to the censored zones.

The inputs that matter

  • 原始图像 and 遮罩 - the picture and the mask defining what to cover. Mask values above zero are fair game.
  • 覆盖模式 - 图像 or 马赛克. Image replacement needs 覆盖图 connected.
  • 遮罩膨胀 - pixels of growth around each region. Start at 4–8 for faces; 0 leaves hard edges.
  • 马赛克数量 - the block size for mosaic mode. 5 is the default and honestly the right neighborhood; huge values look like a coding glitch.

Outputs: 处理后图像 (IMAGE) and 处理后遮罩 (MASK).

Installing

cd ComfyUI/custom_nodes
git clone https://github.com/zml-w/ComfyUI-ZML-Image

restart, or ComfyUI Manager. Needs opencv-python, which is in the pack's requirements.txt and likely already installed. English readers: grab the translation patch (https://github.com/zml-w/ZZZ_ZML_English_Patch) for legible labels.

Common issues

The classic failure: a mask that's all alpha or wildly noisy makes findContours produce either one enormous region or thousands of fragments. Convert masks to a clean black-and-white before feeding them in. Also, if your replacement image doesn't cover the mask (or is connected but the mask is larger), you get partial coverage - inflate the mask and check the output mask socket, which tells you the truth about what got covered. And note the author's own caveat: this pack is one person's hobby, the frequently-used nodes are polished, and the rest "may have bugs." Censoring tools get a lot of use in this pack's ecosystem, so this one's had the bugs shaken out - but it's still worth a quick test on a copy before you censor a whole batch.

Categoryimage/ZML_图像/工具

Inputs (8)

NameTypeDefaultDescription
原始图像IMAGE
遮罩MASK
覆盖模式COMBO2 options: 图像, 马赛克
拉伸图像BOOLEANfalse
马赛克数量INT51–256
遮罩缩放系数FLOAT1.000.1–5
遮罩膨胀INT00–128
覆盖图optIMAGE

Outputs (2)

NameTypeDescription
处理后图像IMAGE
处理后遮罩MASK