Extracting sprites from sprites maps and quantizing them using a specified palette.
The scripts are written in Python and require the following libraries:
schema
PyYAML
Pillow
colormath
functools32
scipy
numpy
cv2
The script unpackSprites.py
allows you to extract sprites from a sprite
map. You can specify maximum and minimum size of sprites and resize
the resulting sprites.
unpackSprites.py sprite-map.png
Extract sprites from the image file sprite-map.png
. By default,
extracted sprites are named like sprite-map-001
and stored in a
subdirectory named sprite-maps_sprites
but this is configurable
through options -f
or --format
and -d
or --directory
.
- Automatic selection of background color
- Select size of extracted sprites
- Rescale the sprites
The script beadifySprite.py
converts any input image file into a
corresponding bead image file using some predefined palettes.
beadifySprite.py sprite1.png sprite2.png
Quantize list of files sprite1.png
and sprite2.png
. The default
configuration file is the file config.yml
but this can be specified
by option -c
or --config
. By default, the script use the palette
specified in the configuration file under the option default
but
this can be overriden by specifying its name with option -p
. You can
specify any palette you want under the option pallettes
in the
configuration file. Currently, 3 palettes are available: Perler
,
Hama
and Nabbi
. Palette can inherit list of colors from other
palettes.
- Perler, HAMA and Nabbi palettes available
- Easy customization of palettes through configuration file
- 2 color distances implemented so far
The sprite map is taken from the Spriter Resource. First extract the sprites from the map:
./unpackSprites.py -m 70 examples/ItemsOverworld.png
and specify a minimum number of pixels per sprite to avoid false positives.
Same thing but resize sprites by a factor of 10:
./unpackSprites.py -m 70 -r 10 --format '{filename}-resized10-{num:0>{length}}.png' examples/ItemsOverworld.png
Next, quantize the sprites with the Perler palette and the two available color distances:
./beadifySprite.py -m 10 examples/ItemsOverworld_sprites/ItemsOverworld-??.png
./beadifySprite.py -m 10 -d rgb examples/ItemsOverworld_sprites/ItemsOverworld-??.png --format '{filename}-{palette}-rgb.{ext}'
and magnify the resulting sprites.
Compare the results:
Extracted sprites:
After quantization with Lab distance:
After quantization with RGB distance:
The color codes from Perler, HAMA and Nabbi palettes are taken from this spreadsheet but some are still missing.
The script unpackSprites.py
takes large parts from this gist