ComfyUI Node Runs on cloud

Blockify Mask

Snap a mask to a coarse block grid

By kijai·Created 3 years ago·Updated about 9 hours ago· 2,930
Blockify Mask
  • masks
  • mask
block_size32
devicecpu

BlockifyMask takes a mask and quantizes it to a grid of square blocks - any block that touches the original mask gets filled solid. You feed in a soft, arbitrary shape and get back a chunky, blocky version of it. That sounds destructive, and it is, on purpose: some parts of a diffusion pipeline don't operate at pixel granularity, and a mask that respects the same block grid they do behaves better than a pixel-perfect one that straddles block boundaries.

What it's for

The node's description is exact: "Creates a block mask by dividing the bounding box of each mask into blocks of the specified size and filling in blocks that contain any part of the original mask." So it finds the bounding region of your mask, tiles it into block_size-square cells, and turns on every cell your mask overlaps.

Where that's useful: things that work in blocks or tiles rather than pixels. Latent operations run at a downsampled grid (the VAE compresses spatial resolution, so one latent cell is a block of pixels), and attention/tiling schemes divide the image into patches. If you want a mask that aligns cleanly to that structure - so an attention edit or a block-level operation applies to whole cells instead of clipping through the middle of them - blockifying gets you there. It's also just a fast way to build a deliberately coarse, low-fidelity mask when a soft precise one is overkill or is causing edge artifacts.

The inputs and output

  • masks - the mask(s) to blockify.
  • block_size (default 32) - the cell size in pixels. Bigger blocks mean a coarser, chunkier result that covers more area beyond the original shape; smaller blocks hug the shape more tightly. This is the one dial that matters, and the right value usually matches whatever grid you're aligning to (a VAE's factor, a tile size).
  • device (optional, default cpu) - cpu or gpu. Leave it on cpu unless the mask is large enough that the operation is a bottleneck; then gpu can speed it up.

The output is the blockified mask.

How to install it

It's in kijai's KJNodes pack.

  • ComfyUI Manager - search KJNodes for ComfyUI, install, restart.
  • Manual - cd ComfyUI/custom_nodes && git clone https://github.com/kijai/ComfyUI-KJNodes, then pip install -r ComfyUI-KJNodes/requirements.txt, restart.

No models or dependencies.

Common issues & troubleshooting

The mask covers way more than my shape. That's what blockifying does - any block touching the mask fills entirely, so a thin diagonal line can light up a whole row of blocks. Use a smaller block_size to hug the shape more tightly, or accept the spread if the point was a coarse mask.

Blocky edges show up in the result. If you're using this for ordinary inpainting where you wanted a soft, natural boundary, this is the wrong tool - the hard block grid is the feature, not a bug. Blur/feather a normal mask instead. Blockify is for when block-alignment matters more than smooth edges.

No alignment benefit. The win only lands if block_size matches the grid you're aligning to. Pick a size that corresponds to your latent downsample factor or tile size; an arbitrary size just gives you a chunky mask with no structural payoff.

Multiple separate masks. It blockifies per mask region using each one's bounding box, so distinct blobs get their own blocked areas rather than one giant bounding box over everything - expected behavior, not a merge.

CategoryKJNodes/masking

Inputs (3)

NameTypeDefaultDescription
masksMASK
block_sizeINT328–512Size of blocks in pixels (smaller = smaller blocks)
deviceoptCOMBOcpuDevice to use for processing

Outputs (1)

NameTypeDescription
maskMASK