MosaicMask
Auto-detect the mosaic and let it build the inpaint mask
- image
- mosaic_mask
The most annoying step in any "regenerate the censored bit" workflow isn't the sampling - it's drawing the mask. You zoom in, you trace around a censor box by hand, you feather it, you hope the edges land right. MosaicMask does that job for you: feed it an image and it finds the mosaic/censor regions automatically and hands you a ready-made mosaic_mask that you wire straight into an inpaint.
Why bother with a mask at all, in the age of instruction-edit models? Because masked inpainting is the one technique that leaves everything outside the masked region pixel-identical. An edit model takes the whole frame into context and quietly drifts the parts you didn't ask to touch. If your whole goal is "change exactly the blurred-out rectangle and nothing else," a mask-based inpaint on an SDXL or Illustrious fine-tune is still the right tool, and this node is the fastest way to build that mask without touching a brush.
How it works
It's pure OpenCV, no model, no download, no API key. The repo ships 16 grid templates in a grids/ folder (5×5 up to 20×20 pixels). MosaicMask runs Canny edge detection, then slides each grid template over the result with cv2.matchTemplate and looks for the tell-tale checkerboard pattern of mosaic cells. Wherever a template scores above a threshold, it paints that region into a coverage map, then keeps only the top_n largest connected blobs. The output is a clean binary MASK tensor in the standard ComfyUI [batch, height, width] shape.
There are a couple of optional tuning knobs in the code - a detection threshold and the min/max grid size to search - but the defaults are sane and the three required inputs are all a beginner needs.
The inputs that matter
- image - any IMAGE, batched or not. It runs per-frame, so it'll happily chew through a whole video's frames if you want per-frame masks.
- top_n (default 1) - how many separate censored areas to keep, sorted by area. If a frame has three censor boxes, set it to 3 or you'll only get the biggest one masked.
- kernel_size (default 3) - how many pixels the mask expands beyond the detected area. A small expansion keeps the inpaint from eating the edges of the region.
Output: mosaic_mask (MASK), which you'd typically feed into a mask-blur or smoothing step, then into VAE Encode for Inpainting / Set Latent Noise Mask.
Install
Easiest via ComfyUI Manager - search "ComfyUI-Mosaic-Mask". Or the manual route:
cd ComfyUI/custom_nodes
git clone https://github.com/okgo4/ComfyUI-Mosaic-Mask
Restart ComfyUI. The only dependency is opencv-python-headless>=4.8, which Manager installs for you, and there are no model files to fetch - the grid templates ship inside the repo. This is about the lightest custom node you'll ever install.
Gotchas
The README is blunt about the big one: it strongly recommends a mask-smoothing node (it names "Mask Smooth Region") after MosaicMask, because sampling on this hard-edged binary mask can turn the inpainted image black. That's the classic sharp-mask-edge artifact - the latent gets a raw binary boundary instead of a feathered one, and the sampler punishes you. Feed the mask through a blur/smooth node and the problem disappears.
Second: detection only works for mosaic grid cells in the 5×5 to 20×20 pixel range. Tiny mosaics on low-res crops fall below the smallest template and nothing gets found - you'll get an all-black mask and, silently, no inpainting. If your source is small, upscale it before running the detector.
Third: it detects grid censoring. Solid color bars, deep blurs, and heavy pixelation without a regular grid may not trigger it. For those, you're still hand-painting.
It's a narrow tool with one job, but for its niche - turning "find the censor boxes" from a manual chore into a one-click mask - it does exactly what it says, and it's honest about its limits.
Inputs (6)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| top_n | INT | 11–10 | — |
| kernel_size | INT | 30–100 | — |
| thresholdopt | FLOAT | 0.300–1 | — |
| min_grid_sizeopt | INT | 105–20 | — |
| max_grid_sizeopt | INT | 205–20 | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| mosaic_mask | MASK | — |