ComfyUI Node

Image Grid Slicer

Slice One Image Into a Grid of Tiles (and Feed a Batch)

By marcoc2·Created 2 years ago·Updated 5 months ago· 1
Image Grid Slicer
  • image
  • image_list
grid_x2
grid_y2

Some jobs in ComfyUI start with "chop this image into pieces." Dataset prep wants tiles instead of one giant file. Sprite-sheet workflows want individual frames. Tile-based upscaling wants overlapping crops to process one at a time. ImageGridSlicer is the boring, reliable knife for that: give it an image, tell it how many columns and rows, and it hands you a list of tiles.

It comes from AnotherUtils (marcoc2/ComfyUI-AnotherUtils), the single-author utility pack by marcoags. No models, no special dependencies - just a tensor split. Don't expect more than that, because that's the whole appeal: it does one thing, does it in pure PyTorch, and doesn't drag a requirements.txt into your environment.

How it works

The mechanism is refreshingly dumb. It takes the image (shape [B, H, W, C]), strips the alpha channel, computes tile_width = width // grid_x and tile_height = height // grid_y, then crops in row-major order - left to right, top to bottom. Two details are worth knowing because they're the difference between "it worked" and "why are my edges cut off":

  • If your width isn't evenly divisible by grid_x, the last tile in each row is extended to the full image edge instead of being truncated. So a 100px-wide image split into 3 columns gives tiles of 33, 33, 34 - nothing gets discarded, but the last column is slightly larger.
  • It also strips alpha. An RGBA input becomes RGB tiles. If you actually need the alpha, slice the alpha yourself first.

The inputs

There are only three, and you'll only touch two of them:

  • image - any batch of images; each frame in the batch gets sliced, so [B, H, W, C] in gives you B × grid_x × grid_y tiles.
  • grid_x / grid_y - columns and rows, 1–100 each. 2×2 for a four-way split, 4×4 if you're cutting up a sprite sheet.

What comes out

A single image_list output that is literally a Python list of single-image tensors (the node sets OUTPUT_IS_LIST = True). That's the one gotcha: most ComfyUI batch nodes want a stacked batch tensor, not a list. The AnotherUtils pack knows this and ships the converters to match - run the list through ImageListToBatch if your next node expects a batch, or feed individual tiles to BatchToImageList if you need them one at a time.

Installing it

Same as every node in the pack:

cd ComfyUI/custom_nodes
git clone https://github.com/marcoc2/ComfyUI-AnotherUtils.git

Restart ComfyUI, or search "AnotherUtils" in ComfyUI Manager. No models, no extra pip packages.

Where people get burned

The list-vs-batch mismatch is the #1 confusion, so repeat after me: the output is a list. Also, if you recombine tiles later, remember the last-row/last-column expansion - tiles aren't all identical size when the dimensions don't divide evenly, and a naive torch.stack of them will throw. Either pick grid counts that divide your image exactly, or plan to pad when you stitch back. For dataset work that's usually fine, since most dataset loaders don't care about exact tile dimensions anyway.

CategoryAnotherUtils/image_processing

Inputs (3)

NameTypeDefaultDescription
imageIMAGE
grid_xINT21–100
grid_yINT21–100

Outputs (1)

NameTypeDescription
image_listIMAGE