Nodes/ComfyUI Fast Mosaic Detector/Fast Mosaic Detector
ComfyUI Node

Fast Mosaic Detector

Hand your inpainting pipeline a precise mask of the censored pixels

By yano·Created 10 months ago·Updated 10 months ago· 6
Fast Mosaic Detector
  • image
  • MASK
  • INT
hsv_skin_h_low35
hsv_skin_h_high160
hsv_skin_s_threshold25
gradient_threshold2.50
ratio_threshold2.74
histogram_threshold0.10
mosaic_length_min4
mosaic_length_max40
intersection_margin5
gradient_band_height1
gradient_band_half_width15
modeHYBRID
processing_backendAUTO
max_workers8
fast_recall_boost0.90
roi_margin_px24
refine_logicreplace
refine_frame_stride3
roi_merge_dilate_px8
roi_max_count5
min_mask_pixels200
frame_cover_threshold0.30
adaptive_roi_area_ratio0.25
adaptive_roi_min_side48
roi_downscale_large0.75
roi_aspect_ratio_max3.0
roi_min_short_side12

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. replace is 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 → raise roi_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.

Categoryfast-mosaic-detector

Inputs (28)

NameTypeDefaultDescription
imageIMAGE
hsv_skin_h_lowINT350–180
hsv_skin_h_highINT1600–180
hsv_skin_s_thresholdINT250–255
gradient_thresholdFLOAT2.500–20
ratio_thresholdFLOAT2.740–20
histogram_thresholdFLOAT0.100–1
mosaic_length_minINT42–64
mosaic_length_maxINT403–128
intersection_marginINT50–50
gradient_band_heightINT11–8
gradient_band_half_widthINT151–64
modeCOMBOHYBRID3 options: FAST, ACCURATE, HYBRID
processing_backendCOMBOAUTO3 options: AUTO, CPU, TORCH
max_workersINT80–32
fast_recall_boostFLOAT0.900.1–2
roi_margin_pxINT240–128
refine_logicCOMBOreplace3 options: replace, union, intersect
refine_frame_strideINT31–12
roi_merge_dilate_pxINT80–64
roi_max_countINT51–32
min_mask_pixelsINT2000–10000
frame_cover_thresholdFLOAT0.300.05–0.95
adaptive_roi_area_ratioFLOAT0.250–1
adaptive_roi_min_sideINT484–512
roi_downscale_largeFLOAT0.750.4–1
roi_aspect_ratio_maxFLOAT3.01–10
roi_min_short_sideINT121–128

Outputs (2)

NameTypeDescription
MASKMASK
INTINT