Sprite Sheet Extract
Cut pixel art apart so AnimateDiff can chew it
- image
- sprites
- sprite_map_json
- summary_json
You found a sprite sheet - a row of walking-cycle frames on one image - and you want it as separate frames. ComfyUI's image handling wants a batch; the sheet is one big image with invisible seams. MKRSpriteSheetExtract is the node that does the cutting, and it does it without you drawing a single mask.
The mechanism is connected-component segmentation. It builds a mask of "what's a sprite" from either the alpha channel or a color key, then finds each separate blob of pixels, and crops a padded box around every blob big enough to count. Each crop becomes one image in the output batch, in the order you asked for. It's the same idea as a shoebox sprite unpacker - the alias literally says "shoebox sprite extract" - but inside the graph.
The inputs that matter
- source_mode -
alphaorcolor_key. Alpha works when the sheet has transparency. Color key works on cleanly flat-backgrounded sheets, where you give it the exact background color. - key_color - the magic-magenta default
#ff00ffis the classic game-dev transparent color, which tells you what the author expects you to feed it. If your sheet has a different flat background, put that here instead. - key_threshold - how close to the key color counts as background. 0.08 is tight; raise it if your background has anti-aliasing fringes.
- min_sprite_pixels - ignore blobs smaller than this. Default 4. This is your noise filter; set it higher when dust in the scan is making phantom sprites.
- padding - extra pixels around each crop. Default 1 keeps sprites from touching their neighbors' pixels.
- sort_mode -
top_left,left_to_right, orarea_desc. For an animation sheet you usually want a consistent row-major order so the frames come out in sequence.
What comes out
sprites is an IMAGE batch - feed it straight into an AnimateDiff or a per-frame img2img pass. sprite_map_json records where each sprite lived in the original sheet, and summary_json reports what got found. Keep the map if you ever need to write results back into the same layout.
Installing it
Part of criskb/MKRShift_Nodes from Cris K B. ComfyUI Manager search "MKRShift_Nodes", or:
cd ComfyUI/custom_nodes
git clone https://github.com/criskb/MKRShift_Nodes
Restart. No pip requirements, no models - it's numpy and torch operations on the image tensor.
Where it bites
Color-key extraction is only as clean as your background. Jpeg artifacts and soft shadows around the sprite will read as "not the key color" and you'll get jagged edges or stray blobs - that's why min_sprite_pixels and key_threshold exist. Sprites that touch each other (shared outlines, no gap) get merged into one crop, because connected components see them as a single blob; if your sheet has touching sprites, add padding or re-export the sheet with a gap. For real production pixel art this is a solid time-saver; for loosely packed sheets with overlapping frames you'll still be doing manual crops.
Inputs (8)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| source_mode | COMBO | alpha | 2 options: alpha, color_key |
| alpha_threshold | FLOAT | 0.050–1 | — |
| key_color | STRING | #ff00ff | — |
| key_threshold | FLOAT | 0.080–1 | — |
| min_sprite_pixels | INT | 41–4096 | — |
| padding | INT | 10–64 | — |
| sort_mode | COMBO | top_left | 3 options: top_left, left_to_right, area_desc |
Outputs (3)
| Name | Type | Description |
|---|---|---|
| sprites | IMAGE | — |
| sprite_map_json | STRING | — |
| summary_json | STRING | — |