Nodes/ComfyUi_zaknak_nodes/Censor Bars By Mask
ComfyUI Node

Censor Bars By Mask

The anime-style bar censor, driven by any mask

By zaknak·Created 6 months ago·Updated 6 months ago· 0
Censor Bars By Mask
  • image
  • mask
  • image
mask_batch_modematch_image_batch
bar_color_r0
bar_color_g0
bar_color_b0
opacity1.00
angle_modeauto
angle_deg0
angle_offset_deg90
bar_width18
bar_spacing8
width_jitter3.0
spacing_jitter2.0
seed0

You know the look: a face, a sign, a license plate hidden under parallel black bars - the censorship stripe that shows up in anime, Japanese print media, and news broadcasts alike. This node recreates it in ComfyUI, pointed at exactly what you want by a mask, and leaves every pixel outside that mask untouched. If you've been doing this with a flat fill or a soft brush, this is the upgrade.

It ships in the same small pack as Mosaic By Mask - the two are the pack author's "hide something by mask" pair. Mosaic pixelates; this one lays down stripes. Which you want is an aesthetic call, but the bar look reads unmistakably as "censored" in a way mosaic sometimes doesn't.

How it works

You feed it an image and a mask. The mask's non-zero region is the target - it's used as a placement basis for the bars, not painted over directly. The node finds the region's bounding box, then in angle_mode = auto runs a quick PCA over the mask's pixels to estimate its long axis, so bars automatically run perpendicular to a thin region (a face, a plate). angle_mode = manual lets you set the angle yourself with angle_deg.

Bars are drawn as a stack of parallel stripes along that axis. Each bar's bar_width and bar_spacing get a small random nudge from width_jitter and spacing_jitter, driven by seed, so the result looks organic instead of laser-cut. Everything is clipped to the mask, so bars never bleed outside it, and the final composite is an alpha blend at opacity with your chosen bar_color_r/g/b (default black). It's all pure torch tensors - fast, no models involved.

The inputs that matter

  • image + mask - the pair. White mask areas are what get hidden.
  • angle_mode - auto (PCA, good enough for most regions) or manual.
  • bar_width (18) and bar_spacing (8) - chunkier bars and tighter spacing make it look more like the classic censor stripe.
  • seed - jitter reproducibility; fix it if you're comparing runs.
  • opacity - 1.0 is solid; lower lets the image ghost through.

The single output, image, is the composited result - wire it to a preview or a save node.

Install

It's part of ComfyUi_zaknak_nodes. In ComfyUI Manager, search for that pack title and install, or:

cd ComfyUI/custom_nodes
git clone https://github.com/zaknak/ComfyUi_zaknak_nodes

Then restart ComfyUI. No model downloads, no extra Python deps for this node - the pack's only real dependency (tomli) exists for its LLM nodes.

Where it fits in a workflow

Put it after VAE Decode, with a mask from any MASK-producing node - Segment Anything via Impact Pack, a mask editor, or a face-detection mask. Common uses: anonymizing faces or plates before you post a generation, building parody or "censored preview" thumbnails, or just replicating the anime censor aesthetic for a joke that's funnier than it should be.

Troubleshooting

  • Empty mask, or opacity = 0: the node returns the input image unchanged - no error, which is nice, but also a silent way to wonder why nothing happened.
  • Bars look wrong direction: auto mode falls back to 0° for tiny, near-circular, or low-contrast masks where PCA has no strong axis. Give it a manual angle in those cases, or nudge angle_offset_deg (default 90, which is the perpendicular-to-axis look).
  • It prints timing lines to the ComfyUI console ([CensorBarsByMask] preprocess_mask: ...). Harmless - the author added them for debugging, and they're genuinely handy when a batch is slow.
  • Mask batch size mismatch: if your mask batch isn't 1 or equal to the image batch, it errors. Switch mask_batch_mode to merge_batch_to_one to collapse several masks into one region.
Categoryzaknak/image

Inputs (15)

NameTypeDefaultDescription
imageIMAGE
maskMASK
mask_batch_modeCOMBOmatch_image_batch2 options: match_image_batch, merge_batch_to_one
bar_color_rINT00–255
bar_color_gINT00–255
bar_color_bINT00–255
opacityFLOAT1.000–1
angle_modeCOMBOauto2 options: manual, auto
angle_degFLOAT0-180–180
angle_offset_degFLOAT90-180–180
bar_widthFLOAT181–512
bar_spacingFLOAT80–512
width_jitterFLOAT3.00–256
spacing_jitterFLOAT2.00–256
seedINT00–2147483647

Outputs (1)

NameTypeDescription
imageIMAGE