Nodes/comfyui_bmad_nodes/Merge Latent Batch Gridwise
ComfyUI Node Runs on cloud

Merge Latent Batch Gridwise

Stitch a batch of latents back into one image — the other half of the grid trick

By bmad4ever·Created 3 years ago·Updated 9 months ago· 70
Merge Latent Batch Gridwise
  • batch
  • mask
  • LATENT
rows1
columns1

This node exists to be the second half of a two-node trick. The first half is MaskGrid N KSamplers Advanced, which samples a grid of regions and hands you a batch of latents - one per cell. This node takes that batch and glues it back together into a single latent arranged as a rows × columns grid, so you can decode one image instead of a stack of fragments.

You can technically use it with any latent batch that happens to represent grid cells, but honestly: it's built to be the pair for the MaskGrid node, and that's where you'll reach for it. Together they give you DIY per-region generation - different prompt or denoise behavior per cell - without installing a regional-conditioning framework.

How it works

The mechanism is simple, which is why it's reliable. You give it a latent batch, a mask (used only for its dimensions), and rows/columns. The mask's pixel size is divided by 8 to get cell dimensions in latent space - because one latent pixel is 8×8 image pixels - and then each batch entry is copied into its cell:

  • entry index c + r × columns lands in row r, column c

That index math is the one thing to keep in mind: the batch must be ordered row-major, left-to-right then top-to-bottom. That's exactly the order the MaskGrid node outputs, so as a pair they just work.

Inputs and output

  • batch (LATENT) - the grid cells, in row-major order.
  • mask (IMAGE) - purely a size reference for the cell dimensions. It doesn't blend or mask anything; swap in any image of the right size if you like.
  • rows / columns (1–16).

It returns a single LATENT, ready for a VAE Decode.

Where the sharp edges are

The mask's dimensions must line up with what produced the batch. If the latent is 64×64 (512×512 image) and your mask is 512×512, then a 2×2 grid means each cell is 256×256 image pixels - and each batch entry needs to be a 256×256 latent tile. Feed it mismatched sizes and you'll copy data out of bounds or leave dead regions. Also, cells are pasted with no blending - if the cells came from independent samplings you'll see seams. Run the merged latent through MaskOuterBlur or a light mask feather before decoding if the boundaries bother you.

Installing it

Same as every node in this pack:

cd ComfyUI/custom_nodes
git clone https://github.com/bmad4ever/comfyui_bmad_nodes

then restart, or use ComfyUI Manager → search comfyui_bmad_nodes. The pack's pip deps (OpenCV, scikit-image) come with it. No model downloads, no GPU requirements beyond what you already have.

If the node doesn't show up, check the pack's startup banner in your console - it reports exactly which modules loaded and which didn't.

CategoryBmad/latent

Inputs (4)

NameTypeDefaultDescription
batchLATENT
maskIMAGE
rowsINT11–16
columnsINT11–16

Outputs (1)

NameTypeDescription
LATENTLATENT