Fast Mosaic Detector
Hand your inpainting pipeline a precise mask of the censored pixels
- image
- MASK
- INT
The name isn't clickbait. Fast Mosaic Detector finds the mosaic-censored (pixel-blocked) regions in an image or video frame and hands you a binary mask of exactly where they are, plus the estimated block size. If you've ever tried to clean up censored content in ComfyUI, you know the soul-draining part isn't the inpainting - it's hand-painting a mask over every censor bar so the inpaint knows where to work. This node is that step on autopilot. No API, no API key, no model download. It's pure classical computer vision, and it just runs.
Why you'd reach for it
The obvious use is restoration: for anime and doujin content where censor mosaics were baked into the source, the standing recipe is mask → inpaint. The KB's inpainting essay makes the case that mask-based inpainting still uniquely owns bit-identical unmasked pixels - nothing else changes outside the masked region. That only holds if the mask is accurate, and that's exactly what this node produces. It's also useful for QA at scale: feed it a batch of generated frames and get a mask where censoring leaked into your output. Either way, you're replacing a tedious manual step with a graph node.
How it works
Three modes, one node. The author (Takahiro Yano) built two detectors and a bridge:
- FAST - a lightweight, CUDA batch-optimized pass. It computes gradient and histogram features, looks for the repeating grid structure that a mosaic creates, and estimates the block period with overlap histograms on the GPU. Whole batches go through in one shot.
- ACCURATE - a full-frame exhaustive scan in NumPy. Same idea but with skin-color detection (HSV) as an extra cue and no shortcuts. Slow, thorough.
- HYBRID - run FAST over everything, extract the regions it flags as ROIs, then run ACCURATE only inside those boxes and merge the result back. That's the trick that makes the speed numbers work: 840 frames of 640×480 on an RTX 3090 takes ~4s in FAST, ~420s in ACCURATE, and ~40–60s in HYBRID while keeping 85–95% of ACCURATE's precision. That's why HYBRID is the default and honestly the one you should leave it on.
The inputs and outputs that matter
There are a lot of knobs, but only a few you'll actually touch. image takes a single image or a whole batch of frames. mode (FAST / ACCURATE / HYBRID) and processing_backend (AUTO / CPU / TORCH - AUTO just picks CUDA when it's there) are the ones that shape the run. The HYBRID knobs worth knowing:
fast_recall_boost(default 0.9) - raises how aggressive FAST is. If regions get missed, nudge it up.refine_logic(replace / union / intersect) - how refined ROIs merge with the FAST mask.replaceis the default and usually right.roi_aspect_ratio_max(default 3.0) - filters out long thin detections like window bars and text boxes. Author's recommended range is 3–5.roi_downscale_large(default 0.75) - shrinks big ROIs before refinement for speed. Drop it to 1.0 for small mosaics.
The HSV skin parameters (hsv_skin_h_low, etc.) only matter in ACCURATE/HYBRID and only for skin-colored content. Outputs are two: a MASK (a float batch in 0–1, matching the input frames) and an INT giving the detected mosaic block size. The mask wires straight into any inpainting or mask-ops node; the block size is more of a diagnostic, useful if you want to log or filter frames by censor size.
Installing it
One-line via ComfyUI Manager - search "Fast Mosaic Detector" - or manually:
cd ComfyUI/custom_nodes
git clone https://github.com/yano/comfyui-fast-mosaic-detector
Then restart ComfyUI. Dependencies are numpy, opencv-python, torch, torchvision, pillow - you already have all of these if ComfyUI runs. (The pack lists ffmpeg-python in requirements, but the shipped code never imports it; video I/O is expected to come from ComfyUI-VideoHelperSuite, which the author explicitly recommends pairing with for video work.) No weights to download anywhere.
Where people get burned
The README's own notes are the troubleshooting guide, and they're worth taking before you hunt for phantom bugs:
- Mosaics are detectable in roughly a 4–30px block range. Feed it full-HD video and the mosaic is effectively too small - downsample to 0.5–0.75× first so blocks land in that range.
- Anime / non-skin content gets missed by the skin channel - widen the HSV ranges rather than assuming it's broken.
- HYBRID under-detects → raise
fast_recall_boost; over-detects on bars and window frames → raiseroi_aspect_ratio_max.
One honest caveat: this gives you a mask, not a de-censor. The inpaint quality is still on your model and your denoise settings - but at least you're no longer painting that mask by hand, frame after frame.
Inputs (28)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| hsv_skin_h_low | INT | 350–180 | — |
| hsv_skin_h_high | INT | 1600–180 | — |
| hsv_skin_s_threshold | INT | 250–255 | — |
| gradient_threshold | FLOAT | 2.500–20 | — |
| ratio_threshold | FLOAT | 2.740–20 | — |
| histogram_threshold | FLOAT | 0.100–1 | — |
| mosaic_length_min | INT | 42–64 | — |
| mosaic_length_max | INT | 403–128 | — |
| intersection_margin | INT | 50–50 | — |
| gradient_band_height | INT | 11–8 | — |
| gradient_band_half_width | INT | 151–64 | — |
| mode | COMBO | HYBRID | 3 options: FAST, ACCURATE, HYBRID |
| processing_backend | COMBO | AUTO | 3 options: AUTO, CPU, TORCH |
| max_workers | INT | 80–32 | — |
| fast_recall_boost | FLOAT | 0.900.1–2 | — |
| roi_margin_px | INT | 240–128 | — |
| refine_logic | COMBO | replace | 3 options: replace, union, intersect |
| refine_frame_stride | INT | 31–12 | — |
| roi_merge_dilate_px | INT | 80–64 | — |
| roi_max_count | INT | 51–32 | — |
| min_mask_pixels | INT | 2000–10000 | — |
| frame_cover_threshold | FLOAT | 0.300.05–0.95 | — |
| adaptive_roi_area_ratio | FLOAT | 0.250–1 | — |
| adaptive_roi_min_side | INT | 484–512 | — |
| roi_downscale_large | FLOAT | 0.750.4–1 | — |
| roi_aspect_ratio_max | FLOAT | 3.01–10 | — |
| roi_min_short_side | INT | 121–128 | — |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| MASK | MASK | — |
| INT | INT | — |