Nodes/MKRShift_Nodes/Sprite Sheet Extract
ComfyUI Node

Sprite Sheet Extract

Cut pixel art apart so AnimateDiff can chew it

By criskb·Created 7 months ago·Updated 5 months ago· 0
Sprite Sheet Extract
  • image
  • sprites
  • sprite_map_json
  • summary_json
source_modealpha
alpha_threshold0.05
key_color#ff00ff
key_threshold0.08
min_sprite_pixels4
padding1
sort_modetop_left

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 - alpha or color_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 #ff00ff is 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, or area_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.

CategoryMKRShift Nodes/Utility/Pixel

Inputs (8)

NameTypeDefaultDescription
imageIMAGE
source_modeCOMBOalpha2 options: alpha, color_key
alpha_thresholdFLOAT0.050–1
key_colorSTRING#ff00ff
key_thresholdFLOAT0.080–1
min_sprite_pixelsINT41–4096
paddingINT10–64
sort_modeCOMBOtop_left3 options: top_left, left_to_right, area_desc

Outputs (3)

NameTypeDescription
spritesIMAGE
sprite_map_jsonSTRING
summary_jsonSTRING