Blockify Mask(BlockifyMask)
This node accepts one or more inputs of type MASK and processes them on either CPU or GPU devices.
Blockify Mask
The Blockify Mask node receives one or more MASK type inputs and processes them on either CPU or GPU devices.
The Blockify Mask node is a tool for processing masks. It converts continuous input masks into block-like masks composed of squares. Its core functionality involves dividing the bounding box of a mask into a grid of a specified size and filling grid blocks that contain pixels from the original mask as valid areas, thereby generating a pixelated mask effect.
Node Functionality
This node receives one or more MASK type inputs and processes them on CPU or GPU devices. Its technical implementation is as follows: first, it calculates the bounding box of valid pixels for each input mask. Then, it divides this bounding box area into a grid according to the user-specified block_size. For each grid block, if it contains any pixels from the original mask, the entire block is marked as valid (filled). Finally, it outputs a new mask with the same shape as the input but with blockified content.
Node Parameter Description - Blockify Mask
Connection Inputs (Inputs)
| Parameter Name | Data Type | Required | Default Value | Range/Options | Description |
|---|---|---|---|---|---|
masks | MASK | Yes | - | - | masks (input parameter): The original mask(s) to be converted into a block effect. Type is MASK. |
Control Parameters (Parameters)
| Parameter Name | Data Type | Required | Default Value | Range/Options | Description |
|---|---|---|---|---|---|
block_size | INT | Yes | 32 | 8 - 512 (step: 1) | The size of each block. Smaller values result in finer, denser blocks. |
device | COMBO | No | cpu | "cpu", "gpu" | The processing device. |
Output
| Parameter Name | Data Type | Description |
|---|---|---|
| mask | MASK | mask (output parameter): The output blockified mask. Type is MASK. |
Usage Scenarios
In image generation or editing workflows, this node can be used to create stylized selection areas. For example, when aiming to generate an image with a mosaic or pixel art style effect, one could first use a node like SAM to generate a detailed object mask, then blockify it using this node. Finally, this blockified mask can be fed into inpainting or image composition nodes to limit the application area of the special effect.
Notes
Please note that the granularity of the blockification is entirely controlled by the block_size parameter. Smaller values produce finer blocks but will not restore the smooth edges of the original mask. This processing primarily affects the bounding box area of the mask; completely blank masks will remain unchanged.
Blockify Mask Node Source Code Link
The Blockify Mask node is from the ComfyUI-KJNodes node package.
Comments
Sign in with GitHub to join the discussion.