0

EDIT: I am using machine learning with a tensorflow convolutional network to solve this problem. Seems to be working decently. See https://github.com/emnh/opengameart/blob/master/src/train.py for work in progress on solution.

My goal is to split all https://opengameart.org/ sprite sheets automatically, say around 275 000 images, some of which are sprite sheets some of which are not. I would like to:

  • 1: Answer the question: Is this a sprite sheet?
  • 2: Automatically detect bounds for sprite sheets containing sprites separated by background or transparency. This is easy, done already.
  • 3: Automatically detect bounds for dense terrain sprite sheets. This seems harder. I've been trying for a while, with some success. I'm using Python.

This question is similar to Sprite Sheet Detect Individual Sprite Bounds Automatically, but instead of sprites surrounded by transparency which can be flood filled, I'm asking about dense spritesheets, where there is none or almost no transparency, and mostly the whole sheet is filled with terrain tiles.

My current code is at https://github.com/emnh/opengameart/blob/master/src/00-split-sheet.py. In this file you will find both the standard flood fill inside transparency for those sheets which are like that in the method "splitSheet", and the methods "detectSize3X" and "detectSize3Y" are attempting to use opencv with horizontal and vertical line detection to detect the sprite bounds, so they are most relevant for the question.

For example, on https://opengameart.org/content/a-lot-of-metroid-like-blocks-16x16 the script returns the following scores in order, with higher scores indicating higher probability that the size of the sprite is as given. So I'm close, but no cigar on this one (it works on some sheets, not on all). 16 should have highest score for both x and y:

Mostly Dense Tile Sheet

x 16 0.5371577574967406
x 32 0.5552865213882162
x 96 0.5706214689265536
x 64 0.594632768361582
x 48 0.6067796610169491

y 4 0.5123184507799893
y 128 0.5524475524475524
y 16 0.5870012340600576
y 32 0.6037296037296037
y 64 0.6349650349650349

The method I'm using is basically https://docs.opencv.org/3.4/dd/dd7/tutorial_morph_lines_detection.html and then summing up the rows and columns to detect those lines, checking which numbers divide the image width and height, and then giving the score to each of the numbers based on the average sum of the cols/rows it touches. For example for 16x image width 64 I sum up cols 16 32 48 64 and divide by 4.

emh
  • 199
  • 10
  • This seems to be a very poorly defined problem, the description you gave is rife with ambiguity. While it may seem that what you want to compute is obvious to you, you've explained it poorly. You are very unlikely to come up with a deterministic (or randomized) algorithm that computes something you can't express concisely in words. As such, consider rephrasing the problem as a machine learning problem, where the output you want is defined by many examples (labeled data.) Then apply a machine learning algorithm of your choice. – ldog Aug 24 '20 at 19:41
  • @ldog The input is an image and the output is a tuple (width, height) with the width and height of each sprite ((1, 1) if it's not a sprite sheet). I want to try ML for this but I have to study it then. – emh Aug 25 '20 at 05:13

0 Answers0