Skip to main content

spriteutil-KV can detect and create a new image contain the original image sprites

Project description

WHAT THE PROJECT DOES ?

Sprite detection is used to detect sprite sheet of a image

WHY THE PROJECT IS USEFUL ?

  • Project use some module of Python as ImageDraw, Pillow.. to work effectively
  • It does not take much time

HOW TO USE ?

  • Open Terminal
  • pip install spriteutil-KV
  • from spriteutil_Khoi.spriteutil import SpriteSheet

USAGE ?

Find the Most Common Color in an Image

  • Returns the pixel color that is the most used in this image.

  • For example:

from PIL import Image JPEG image image = Image.open('islands.jpg') image.mode 'RGB' find_most_common_color(image) (0, 221, 204) PNG image image = Image.open('metal_slug_sprite_standing_stance_large.png') image.mode 'RGBA' find_most_common_color(image) (0, 0, 0, 0) Grayscale image image = image.convert('L') image.mode 'L' find_most_common_color(image) 0

Find Sprites in an Image

  • The function returns a tuple (sprites, label_map)

  • For example: Sprite (1): [(0, 0), (29, 37)] 30x38

import pprint pprint.pprint(label_map, width=120) [[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0], [0,0,1,1,1,1,0,0,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0], [0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,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,0,1,1,1,1,1,1,1], [0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,1,1,1,1,0], [0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,1,1,0,0], [0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0], [0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0], [0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0], [0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0], [0,0,1,1,1,1,1,1,1,1,0,0,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0], [0,1,1,1,1,1,1,1,0,0,0,0,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0], [0,1,1,1,1,1,1,0,0,0,0,0,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0], [1,1,1,1,1,1,1,1,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0], [1,1,1,1,1,1,1,1,1,0,0,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0], [1,1,1,1,1,1,1,1,1,0,0,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0]]

Draw Sprite Label Bounding Boxes

  • The function create_sprite_labels_image draws the masks of the sprites at the exact same position that the sprites were in the original image. The function draws each sprite mask with a random uniform color (one color per sprite mask). The function also draws a rectangle (bounding box) around each sprite mask, of the same color used for drawing the sprite mask.

  • For example:

from PIL import Image image = Image.open('optimized_sprite_sheet.png') sprites, label_map = find_sprites(image)

Draw sprite masks and bounding boxes with the default white background color.

sprite_label_image = create_sprite_labels_image(sprites, label_map) sprite_label_image.save('optimized_sprite_sheet_bounding_box_white_background.png')

Draw sprite masks and bounding boxes with a transparent background color.

sprite_label_image = create_sprite_labels_image(sprites, label_map, background_color=(0, 0, 0, 0)) sprite_label_image.save('optimized_sprite_sheet_bounding_box_transparent_background.png')

CONTACT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

spriteutil-KV-1.0.4.tar.gz (7.5 kB view hashes)

Uploaded Source

Built Distribution

spriteutil_KV-1.0.4-py3-none-any.whl (7.4 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page