1

Given a sprite sheet with a plain background like this:

Icons

I want to take each individual image off this background and create a file for it. I've looked around and had trouble finding information on how to do this - I cant help but feel there is some simple method. Does anyone have any pointers?

Caveat: Not all sprite sheets are the same format/layout, e.g. this one:

this one

It's laid out slightly differently, and this one is even weirder.

So some challenges:

  1. The background of the sprite sheet varies in colour.

  2. Sprites in the sprite sheet vary in size, and that size cannot be specified ahead of time.

  3. Method must generalize (reasonably well) to thousands of sprite sheets.

Appreciate any help.

thmspl
  • 2,052
  • 2
  • 13
  • 36
eygrr
  • 309
  • 2
  • 10
  • Possible duplicate of someone else asking how to decompose a sprite-sheet: https://stackoverflow.com/questions/9385900/easy-tool-to-decompose-sprite-image – Hoog Jan 02 '20 at 20:59
  • Thanks, looks like this does decompose a sprite sheet but this is more about automating that process or writing a method yourself in-order to automate it for many sheets. – eygrr Jan 03 '20 at 08:30

2 Answers2

0

Taken from: https://www.reddit.com/r/computervision/comments/ej3wgr/extracting_images_from_a_simpleplain_background/

by /u/tzatza

1) detect background color (sample appropriately, say from image edges), one option is with votes in a hashtable (key = r+"-"+g+"-"+b)

2) setup a mask, set all the background pixels to zero in mask within certain color distance of background, set all other mask pixels to 1.

3) optionally: erode the mask once (or twice), then dilate back to remove useless lines.

4) you now have a mask of 0 vs 1, do flood fill on each grouping of 1s to determine the extent of each sprite. Set mask pixels to "2" as you do the flood fill to indicate visited.

5) as you flood fill, track each sprite's min/max x/y and at the end of the flood fill, you have the extents (and a mask) which can be used to crop/store.

eygrr
  • 309
  • 2
  • 10
0

I know this goes against Stackoverlow principles of putting in the entire answer, but may I suggest you search for the "Blue Screen Matting" paper by Alvy Ray Smith & Jim Blinn. There's a copy available here.

They have been in the graphics industry for decades and so "know their stuff".

Simon F
  • 995
  • 7
  • 20