Nodes/ComfyUI-BCNodes/Blockify Mask
ComfyUI Node

Blockify Mask

Masks That Snap to Blocks, Not to Pixels

By 0xBeycan·Created about a month ago·Updated 13 days ago· 2
Blockify Mask
  • masks
  • mask
◄block_size32►
◄devicecpu►

A soft, feathered mask edge is a lie at latent resolution. The VAE works in 8×8 (or 16×16) cells, so half the detail you painted into that gradient is thrown away before the sampler ever sees it. Blockify Mask is the honest version: it turns a mask into the set of square blocks inside its bounding box that contain any part of it.

Why you'd reach for it

Three real uses.

You're masking regions that land on a coarse grid anyway. If the mask is going to be quantised, quantise it on purpose, at a size you chose, instead of letting the downsample to latent space decide for you.

You want a blocky look deliberately. Pixel-art-adjacent inpainting, mosaic edits, deliberately chunky region replacement - a 32 or 64 pixel block size gets you there in one node instead of an image-space round trip through resize and threshold.

You want a cheap, predictable region box. A blockified mask is a legible map of where the action is: which chunks of the frame your detector actually fired on, at a granularity you can read off the node. Handy when a detector is being sloppy and you want to see how sloppy without staring at an antialiased haze.

How it works

For each mask frame separately: it finds the bounding box of every pixel above zero, cuts that box into side // block_size blocks per axis - at least one, so a tiny mask still comes out as a single block - with the remainder going to the last row and column of blocks. A block is set to 1 if any of its pixels was above zero, and 0 otherwise. Then everything outside the bounding box is zero.

The output is hard 0/1, one preallocated frame per input frame. No feathering, no antialiasing, no partial values - which is the point.

Inputs and outputs

Only three things, and two of them matter:

  • masks - the mask batch in.
  • block_size - 8 to 512, default 32. Smaller blocks, finer approximation. The tooltip is refreshingly blunt: "smaller = smaller blocks."
  • device - cpu (default) or gpu. The masks are processed there. CPU is fine for the sizes people actually use; flip it to GPU if you're doing this on a long video batch.
  • Output: mask, one MASK. Wire it wherever the original mask went - to a latent composite, an inpaint conditioning node, Set Latent Noise Mask, or an ImageCompositeMasked through Mask To Image.

One thing to internalise: the blocks are divisions of the bounding box, not of the frame. So the block grid moves with your subject. If the mask's bbox shifts by 10 pixels between two runs, the blocks shift with it - you don't get a frame-aligned lattice. If you need alignment (say you're masking per latent cell), crop or place deliberately, or accept that the grid is subject-relative.

A missing or empty mask returns a (1, 64, 64) zero mask rather than blowing up, which means you can leave it wired in while you're still building the graph.

Install

Same as the rest of the pack - Manager, searching the title ComfyUI-BCNodes, or:

cd ComfyUI/custom_nodes
git clone https://github.com/0xBeycan/ComfyUI-BCNodes
pip install -r ComfyUI-BCNodes/requirements.txt

Restart, then search BCNodes in the node library to see everything at once. The requirements file pulls opencv-python (this is what the pack's mask morphology and hole-filling nodes use) plus postfx and caption-audit, which only back the PostFx and Caption Audit nodes. Delete any leftover ComfyUI-AutoBypass folder from the pack's earlier name.

Gotchas

block_size is an approximation, not a promise: the division is integer, so a 300 pixel bbox at block_size 32 gives you nine blocks of 33-ish pixels, not ten of 30. If you care about exact block counts, check the node's output rather than trusting arithmetic.

Memory is not the problem here - it's per-frame integer counting into one preallocated output - but the node processes the frames in a single call, so a 200-frame 4K mask batch is still a 200-frame 4K mask batch. Do it after you've downscaled, not before.

And don't expect it to keep your feathering. If you blockify and then grow and blur, you're back to a soft edge - which is sometimes exactly what you want (blocky footprint, soft edge for blending), just do it in that order.

CategoryBCNodes/mask

Inputs (3)

NameTypeDefaultDescription
masksMASK—
block_sizeINT328–512Block size in pixels (smaller = smaller blocks).
deviceoptCOMBOcpuDevice the masks are processed on.

Outputs (1)

NameTypeDescription
maskMASK—