Image Grid to Batch (Swwan)
Undo a contact sheet back into frames
- image
- IMAGE
The inverse of a grid concat. You have a sheet - nine frames of an animation, twelve variations someone exported as one PNG, a 3×3 storyboard - and you want the tiles as a batch again so they can go through a sampler, an interpolator, or a video combine.
This is a small node that does exactly one thing, and it's the node that makes the grid round-trip actually workable.
Inputs and outputs
image (IMAGE), columns (INT, default 3, 1–8, tooltip: "The number of columns in the grid"), rows (INT, default 0, 1–8, tooltip: "The number of rows in the grid. Set to 0 for automatic calculation").
One output: IMAGE - the tiles as a batch, in reading order (left to right, top to bottom).
How the split works
Cell width is image_width // columns, integer-divided. Then:
- If
rowsis set, cell height isimage_height // rows. - If
rowsis 0, the node computes cell height asimage_height // columnsand derives rows from that. Yes - the automatic path divides the height by columns, not by an assumed row count. For a square grid (3×3, 4×4) that lands on the right answer. For a 3-column sheet of two rows, it won't, and you'll get cell boundaries in the wrong place.
So the rule of thumb is: pass rows explicitly. The auto path is a convenience for square sheets, and it's very easy to believe it's smarter than it is.
Leftover pixels are cropped away, not distributed: the node slices to rows × columns cells exactly and discards the remainder on the right and bottom. If your grid is 1024 wide with 3 columns, each cell is 341 pixels and one column of pixels is gone. Generate grids at sizes divisible by your column count and this never matters.
Why the round-trip is worth having
Frame sets that arrive as sheets. A lot of shared workflows and dataset exports hand you a contact sheet instead of individual files. This node plus an upscale is the whole ingestion step.
Grid-based batch tricks. Producing 16 variations as a 4×4 sheet in one sampler pass and then exploding them back into 16 frames is a real technique - the sampler works on one image, the batch work happens after.
Verifying a grid concat. Feed Image Concat Multi's batch_grid output into this node and you can confirm the tiles come back in the order you expected. Do that once and you'll never second-guess the layout again.
Where it goes wrong
The obvious one: reading order is assumed, and it's the top-left-to-bottom-right order a normal grid uses. A sheet you built with images placed manually, or a sheet with intentional spacing between tiles, will come apart into slices that each contain a bit of the wrong tile. There's no gutter or margin detection here.
The second one is the rows auto-calculation above. If your extracted tiles look like they're cut at the wrong height - half a face at the bottom of each tile - that's the arithmetic, not your grid.
Third: the output is a plain tensor batch, so every tile is the same size, which is exactly what makes it suitable for a sampler and exactly why it can't reconstruct a sheet with uneven tiles in the first place.
Install
cd /path/to/ComfyUI/custom_nodes
git clone https://github.com/aining2022/ComfyUI_Swwan.git
cd ComfyUI_Swwan
python -m pip install -r requirements.txt
Windows portable:
.\python_embeded\python.exe -m pip install .\ComfyUI\custom_nodes\ComfyUI_Swwan\requirements.txt
Restart ComfyUI, hard-refresh the browser, search Swwan. It lives under Swwan/Advanced/Batch and needs nothing beyond the pack's normal install - no models, no extra wheels, just torch doing a view/permute/reshape.
The one pack-level thing worth knowing if you're upgrading into this: 1.0.0 renamed 56 node IDs that previously overlapped with KJNodes and registers no aliases for the old names, deliberately. It's the right call in the long run - sharing IDs across packs is how you end up debugging someone else's node graph - but it does mean old workflows need the repo's migration pass:
python scripts/migrate_workflow.py old.json --dry-run
Dry-run first. It resolves old IDs to their new Swwan equivalents and saves to a new file, leaving your original alone.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| columns | INT | 31–8 | The number of columns in the grid. |
| rows | INT | 01–8 | The number of rows in the grid. Set to 0 for automatic calculation. |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| IMAGE | IMAGE | — |