Nodes/ComfyUI-UniversalToolkit/Blockify Mask (UTK)
ComfyUI Node

Blockify Mask (UTK)

Turn a soft mask into chunky pixels — for ControlNet and stylized looks

By whmc76·Created about a year ago·Updated about a month ago· 72
Blockify Mask (UTK)
  • masks
  • mask
block_size16
devicecpu
binarizetrue
threshold0.50

Masks are usually smooth, feathered things. Sometimes you want the opposite: a mask that looks like a mosaic, with hard blocky cells - for a pixel-art vibe, a stylized ControlNet input, or just to force a coarse region instead of a fiddly soft boundary. Blockify Mask (UTK) does exactly that: it downsamples your mask into block_size cells and snaps the result back to full resolution, optionally binarizing it to pure black and white.

How it works

The mechanism is tidy and worth knowing: it takes your mask, average-pools it into a small grid where each cell is block_size pixels, then upsamples that grid back to the original size with nearest-neighbor interpolation. The result is a chunky block pattern - every block takes the average value of its underlying mask pixels. That's why a soft feathered mask becomes a set of crisp rectangles instead of a blur.

The device dropdown (cpu or cuda) controls where the pooling runs. The tooltip and code both note that CPU is fine for most cases - this is lightweight work - so pick cuda only if you're batch-processing huge masks and want it off the CPU.

The optional binarize (default on) and threshold (default 0.5) controls do the snap: with binarize on, blocks with an average above the threshold become pure white (1.0) and everything else pure black (0.0). Turn binarize off and you get gray-tone blocks - the softer, "mosaic with shades" look.

The inputs

  • masks - your MASK input (single or batch).
  • block_size (default 16) - the pixel size of each block. 8 = fine detail, 32+ = chunky mosaic. This is the main dial.
  • device, binarize, threshold - as above.

One output: mask, same dimensions as the input, ready for whatever wants it.

Installing it

Standard pack install - ComfyUI Manager → search ComfyUI-UniversalToolkit, or clone into custom_nodes/ and pip install -r requirements.txt, then restart. It's pure torch - nothing extra.

Gotchas

  • block_size 1 or less is a passthrough - the node clamps and just returns the mask. Not an error, but don't expect mosaic at 1.
  • Edge blocks get the average of whatever partial pixels remain - the pooling uses ceil alignment and symmetric padding, so edges are handled gracefully, but corner blocks can be slightly off. Generally invisible at 16+, visible if you crank block_size huge.
  • Binarize on a gray mask loses all softness by design. If your downstream inpainting wanted a feathered boundary, this will give it a hard one - that's the point of the node, so don't be surprised when ControlNet reads a hard edge.

It's a niche tool, but there's no core ComfyUI equivalent with this exact block-and-binarize combination, and for stylized output it's the kind of thing you reach for once and then keep. If you're doing pixel-art or coarsened control signals, this is your node.

CategoryUniversalToolkit/Mask

Inputs (5)

NameTypeDefaultDescription
masksMASK
block_sizeINT161–4096
deviceCOMBOcpu2 options: cpu, cuda
binarizeoptBOOLEANtrue
thresholdoptFLOAT0.500–1

Outputs (1)

NameTypeDescription
maskMASK