Nodes/ComfyUI-Mosaic/Mosaic Detector
ComfyUI Node

Mosaic Detector

Mosaic Detector finds the pixelated parts of an image — no AI, no downloads, just OpenCV

By 1038lab·Created about a year ago·Updated about a year ago· 3
Mosaic Detector
  • image
  • image
  • mask_overlay
  • mask
â—„top_n1â–º
â—„mask_expand0â–º
â—„mask_blur0â–º
â—„invert_maskfalseâ–º
◄overlay_color▾►
â—„overlay_opacity0.5â–º

Mosaic Detector scans an image for pixelated or mosaic-censored regions and hands you a mask of where they are. If you've ever had a screenshot or image with a pixelated block - the standard censor in anime, games, and privacy redactions - and wanted to find it programmatically, this is the node. It comes from the same 1038lab "AI Lab" org as ComfyUI-NodeAlign, and it's the natural companion to the pack's MosaicCreator.

Here's the honest framing up front: this is not AI. It's a classical computer-vision heuristic. There's no model, nothing trained, nothing to download. It finds the structure of a mosaic - the regular grid that pixelation leaves behind - and it will happily find that same structure in brick walls, tiled floors, QR codes, or a screenshot of a spreadsheet. Treat it as a region locator, not a miracle worker. And no, it can't "de-mosaic" anything; it only tells you where the mosaic is. What you do with the mask after that is your call.

How it works

The pipeline lives entirely in OpenCV and runs on CPU, so it's fast:

  1. Convert to grayscale and run a Canny edge detector.
  2. Invert and blur the edges so the grid lines thicken into connected regions.
  3. Template-match against a set of synthetic grid patterns - it generates grid templates for cell sizes 10 through 20 and slides each one over the edge map.
  4. Anywhere the match clears a 0.3 threshold gets rectangle-filled into a mask.
  5. Keep only the top_n largest connected components - this is the real filter, since a lone mosaic block is usually one big blob.
  6. Optionally expand, blur, and/or invert the mask before returning it.

Because the templates only cover cell sizes 10–20 pixels, a mosaic with very large or very small blocks can slip past detection entirely. That's a genuine limitation, not a bug.

The inputs that matter

  • top_n (1–20, default 1) - how many of the largest detected regions survive. The default of 1 means you get only the single biggest mosaic blob; raise it to catch multiple censored regions in one frame.
  • mask_expand (0–64) - dilates the mask by N pixels. Mosaics are usually framed by clean borders, so a bit of expansion helps swallow the region around the grid. 4–8 is a sensible start.
  • mask_blur (0–64, step 2) - feathers the mask edges so downstream nodes don't get a hard cut. The code nudges even values up by one to keep the kernel odd, so don't stress about exact numbers.
  • invert_mask - flips the mask, in case your downstream workflow wants "everything except the mosaic."
  • overlay_color / overlay_opacity - purely visual. They control the colored highlight on the preview output.

Outputs

Three of them. image is your original image, completely untouched. mask_overlay is the visualization - the original with a colored highlight (red, green, blue, yellow, cyan, magenta, or white) drawn over the detected regions at the opacity you set. mask is the actual float mask, and it's the output you care about. Wire it into an inpainting setup to regenerate those regions, into MosaicCreator to re-apply a fresh, uniform censor, or anywhere else you'd feed a mask. Masked inpainting is one of the few places classical masking still beats whole-image edit models, precisely because everything outside the mask stays bit-identical - and this node is how you build that mask automatically.

Install

Identical to the pack's other node:

cd ComfyUI/custom_nodes
git clone https://github.com/1038lab/ComfyUI-Mosaic.git
cd ComfyUI-Mosaic
pip install -r requirements.txt

Then restart ComfyUI. Or just search ComfyUI-Mosaic in ComfyUI Manager. Dependencies are torch, torchvision, opencv-python, pillow, and numpy - all but guaranteed to already be in any working ComfyUI install. No models, no weights, nothing extra to fetch.

Common issues

  • It finds the wrong things. False positives are inherent to template matching - anything with a regular grid texture gets flagged. This is expected behavior, not a defect. Lower your expectations for photos of urban scenes; it's happiest on flat, clean images like screenshots and renders.
  • It finds nothing. If the mosaic's block size is outside the 10–20 template range, or the region is small relative to the image, you'll get an empty mask. Try a different image scale.
  • Silent failure. Like its sibling node, the detector swallows exceptions and returns the original image plus a zeroed mask. If you get no highlight and no mask, the console is where the actual error is hiding.
  • It's essentially unmaintained. One commit, July 2025, no subsequent development. Works as shipped, but don't expect fixes for the limitations above.
Category🧪AILab/🔦Mosaic

Inputs (7)

NameTypeDefaultDescription
imageIMAGE—
top_nINT11–20—
mask_expandINT00–64—
mask_blurINT00–64—
invert_maskBOOLEANfalse—
overlay_colorCOMBO7 options: red, green, blue, yellow, cyan, magenta, +1
overlay_opacityFLOAT0.50–1—

Outputs (3)

NameTypeDescription
imageIMAGE—
mask_overlayIMAGE—
maskMASK—