How to get separate sprites out of one AI-generated scene
Generate one pixel art scene, remove its props with a single edit, and the difference between the two pictures cuts out every prop at its exact size and spot, ready to animate. The prompts, the code and what to clean up.
You generate a game scene you really like. Then you want the bushes to shake and the lantern to swing, and it's one flat picture. Generating each prop on its own gives you a bush that doesn't quite match, at a size that doesn't quite fit. Here's how I got every prop out of one scene instead, at its exact size and in its exact spot, with a clean background behind it.
Every bush, the lantern, the sign and the chest in this clip came out of one generated picture. How they react to the fox is in how to make pixel art props react to the player. This post is about getting them out.
1. Generate the scene as a game screenshot
Ask for a screenshot of a game, not an illustration, and ask for the props as separate game sprites. You get flat, readable props with clear outlines, standing on the ground instead of painted into it. That makes the later steps much easier.
An in-game screenshot of a cozy top-down 2D pixel art RPG, the camera close in on one village street (3/4 top-down view like classic SNES RPGs), not an illustration. A dirt and cobblestone street runs straight across the frame from left to right through the lower middle, wide and empty so the player can walk along it. Along the top: the fronts of three small timber and stone cottages with wooden doors at street level and small windows; one is a little shop with a wooden sign hanging from an iron bracket on its wall. Along the street: three round leafy bushes, a wooden lantern post with a hanging iron lantern, a wooden treasure chest beside a door, a few crates. Two small white chickens pecking on the street. Below the street: short grass and a low wooden fence. Ground made from a 16x16 pixel tileset, buildings and props as separate game sprites on that grid, the player character would be about 32 pixels tall. Clean readable sprites, flat colour blocks, minimal texture noise, dark outlines on props. Even afternoon sunlight. No characters, no UI, no text.
I used Nano Banana Pro, pixel art on, 16:9, with the background included, and asked for 480 x 270. A 16:9 picture from these models is drawn on a grid of about 480 x 270 pixels, so asking for that size keeps every pixel crisp. All four results looked like real game screens. I picked the one with a lantern post, a hanging sign and a chest.
2. Remove the props with one edit
Now edit that same picture and ask for the props to be gone. Name every prop, say what fills in behind it, and say what must stay, like the post the lantern hangs on and the bar the sign hangs from. End with "change nothing else".
Remove these objects and fill where they were with what is behind them (grass, house wall, stone base, dirt street): the three white chickens on the street, all the round green bushes, the iron lantern hanging from the wooden lantern post (keep the wooden post and its arm), the warm glow of that lantern, the hanging wooden anvil sign board and its two short chains (keep the black iron bracket bar on the wall), and the wooden treasure chest. Change nothing else: keep every other pixel, the houses, doors, windows, crates, fence, street and grass exactly where they are, same size, same pixel art style.
Both results of this edit were usable, with the houses, the street and the crates right where they were. That empty street is your background layer, and it's what makes the next step work.
The obvious other way, an edit that keeps only the props on a flat magenta background, didn't work on a scene this busy. It turned the grass magenta and left everything else alone.
3. Find what changed
Download both pictures at the same size, 480 x 270 here, so they line up pixel for pixel. Then compare them. Wherever the edit left a pixel alone, the two match. Wherever a prop was, they don't.
The props light up. You can also see faint outlines of the roofs and walls, because the edit redraws the whole picture and edges move by a pixel here and there. Those faint lines are why I don't cut everything that changed in one go. I draw a rough box around each prop by eye and only look inside it.
4. Cut each prop out
Inside its box, the biggest piece that changed is the prop. Close the small gaps where the prop happens to look like the ground behind it, fill the holes, and copy those pixels out of the original scene:
def cut_prop(scene, plate, box):
# scene, plate: the two pictures as float RGB arrays on the same grid. box: x, y, w, h around one prop.
x, y, w, h = box
diff = np.abs(scene[y:y + h, x:x + w] - plate[y:y + h, x:x + w]).sum(-1)
changed = ndimage.uniform_filter(diff, 3) > 70 # smooth out single noisy pixels
pieces, n = ndimage.label(changed)
sizes = ndimage.sum(changed, pieces, range(1, n + 1))
mask = pieces == 1 + np.argmax(sizes) # the biggest changed piece is the prop
mask = ndimage.binary_closing(mask, iterations=2) # close gaps where the prop looks like the ground
mask = ndimage.binary_fill_holes(mask)
ys, xs = np.nonzero(mask)
y0, y1, x0, x1 = ys.min(), ys.max() + 1, xs.min(), xs.max() + 1
rgba = np.zeros((y1 - y0, x1 - x0, 4), np.uint8)
rgba[..., :3] = scene[y + y0:y + y1, x + x0:x + x1]
rgba[..., 3] = mask[y0:y1, x0:x1] * 255
return x + x0, y + y0, rgba # where it sits in the scene, and the sprite
Run it on both pictures as float RGB arrays (np.asarray(img.convert("RGB")).astype(float)), once per box. You get each sprite and the spot where it sits in the scene, so you can put it back exactly where it was.
5. Trim what came along
A prop comes out with whatever the edit changed around it. Here that was:
- The lantern brought a bit of its arm and its glow, since I asked for the glow to go too.
- The sign brought its bracket bar and some wall, because the edit redrew the bar.
- The chickens came with the dirt shadow under their feet.
- The chest had a green rim from the grass.
I cut the rows that belong to something else (the arm, the bar), and dropped pixels in a color that belongs to the ground (green on the lantern and the chest). A pixel that is just the background made a bit darker or lighter is a shadow or a glow. I dropped those where it was clear, like the lantern's glow and the chickens' dirt, and drew light and shadows in code, so they stay put when the prop moves.
Check that part by eye. Dark leaves on a bush in front of green grass look exactly like a shadow on that grass, and an automatic check cut a hole in a bush on my first try.
6. Make the moving things on their own
Anything that walks around needs more than one pose, and the scene only has one. The chickens I cut out were muddy too. So I made them again as a sheet of four poses, with the street as the only style reference. That keeps them at the same pixel size and in the same palette as the rest of the scene.
Four small white hen sprites for a top-down 3/4 view pixel art RPG, in a 2x2 grid, all facing left, same hen design and scale. Row 1: hen standing, hen pecking the ground with its head down. Row 2: hen running with wings flapped up, hen walking mid-step. Plump round white body, small red comb and wattle, yellow-orange beak and legs, a few light grey feather lines on the wing and tail, clean dark brown 1 pixel outline. Tiny low-resolution sprites about 20 pixels tall, in the same chunky pixel scale and warm muted palette as the reference village scene. One hen centered in each cell, generous empty space, no shadows, no ground, no text, no grid lines.
Three of the four poses came back facing right instead of left, so I flipped the odd one to match. I asked for two sheets and one came back at the scene's size. The other was a bit bigger, so check the size before you use a sheet.
Good to know
- What it cost. With Nano Banana Pro at 16 credits a picture: 64 for four scenes, 32 for two versions of the edit, 32 for two chicken sheets. 128 credits for a whole street of props, plus 16 for the magenta edit that didn't work.
- One picture per scene. The edit only lines up with the picture it was made from. Pick your favorite scene first, then make the edit from that one.
- Name what stays. Without "keep the wooden post and its arm", the edit can take the post with the lantern.
- It works for anything you want to animate. Doors, signs, plants, crates. Remove it with an edit and the difference gives you its exact shape.
Where to next
- How to make pixel art props react to the player, what these props do once they're cut out
- How to keep your game art consistent with AI, for making more props that match the scene
- How to fix and recolor pixel art with an AI agent, for small fixes to a sprite after you cut it out
More SpriteCook guides
All guides
An AI Assistant That Helps You Make Game ArtAsk how to make a sprite, get pointed to the right tool, ask about a specific asset, or have it set up a generation for you. Here's how the in-app assistant works.