1 Comment

Average hue determination – (Pokédex part 2)

How do I sort a series of images by color? See the previous post for the motivation here.

My first iteration was just to take the average of all the opaque pixels of the image. It was a start, but I knew this wasn’t going to be sufficient. That only gives me a single color. It also might give me a completely wrong in-between color if a Pokémon is half one color and half another.

Is Smoochum yellow or pink?

Is Smoochum yellow or pink?

So then I thought to calculate the hue of each pixel and divide them up into buckets to make a histogram of hues. I could then choose a maximum (or multiple maxima if I wanted to classify it under multiple distinct hues).

Immediately I saw a problem though: if the main color of a Pokémon lay roughly between two buckets, samples might be split between those two buckets, leading another bucket (representing a less important color) to be the “winner”.

There’s probably a correct and complex mathematical solution to this problem, but the immediately obvious thing to do was to make buckets overlap adjacent buckets. So one pixel sample could end up in multiple adjacent buckets and help count towards both their scores.

So I set about implementing that, but started with only choosing one bucket just to simply things. One of the first things I noticed was the miscategorization of many Pokémon. Umbreon for instance, was lumped with the blue Pokémon:

UmbreonWithBlue

Mousing over the Umbreon sprite in photoshop, I could see it was dominated by a very unsaturated blue hue (its gray body). I kind of wanted it in the yellow category. So I added a saturation threshold below which I wouldn’t consider pixels.

This helped, but I still noticed some problems. Latias, who is pink/red, was categorized with the purple Pokes. In Photoshop, Latias’ slightly purple upper body was below my saturation threshold, so what was the problem?

LatiasSaturation

Stepping through the debugger, I noticed that the saturation values being calculated for the barely purple pixels were close to 100%. It turns out that System.Drawing.Color.GetSaturation uses the HSL representation, not HSV (despite the documentation saying otherwise). I replaced its implementation with a proper HSV saturation, and the problem was fixed.

I had to lower my saturation threshold to around 10% to correctly categorize some Pokes. But that put Zoroark amongst the purples, due to his just slightly purple dark body:

ZoroPurple

I realized that it was probably a better idea to weight the samples based on saturation. That fixed Zoroark’s problem:

ZoroRed

But oh no: Sylveon, who had previously been categorized correctly, was now in the blues. She’s generally pink, but her blues are just saturated enough to outweigh that.

SylveonNowBlue

So I put a max on the saturation weight at 60%, and that was enough to tip the scales in her favor and bring her back to pinks:

SylveonBetter

But now the pink Mewtwos were in the green zone:

MewTwoGreen

Inspecting in Photoshop, I saw that the sprite is ringed by a greenish outline that is dark, but highly saturated.

MewGreenOutline

Of course… dark colors can be highly saturated (look here). So my final tweak was to instead weight by the product of saturation and brightness (value). Mewtwo is in good company now:

MewTwoGood

Finally, it was time to allow for a Poke to appear in multiple color categories. I played around with this for a bit, and came up with the following: I choose a bucket that is at least 50% of the biggest bucket, and whose adjacent buckets are less than itself (i.e. it must be a local maximum). It seems suitable.

The final result looks something like this, with very quick scrolling through the list:

Final

Unfortunately, it has turned out not to be all that useful. It still takes a while to find the Pokémon you want.

Advertisements

One comment on “Average hue determination – (Pokédex part 2)

  1. […] I wondered how you could quickly identify an unfamiliar Pokémon just based on what it looks like. That’s when I came up with the idea of sorting the Pokémon in my database by their hue. So you could quickly scroll to the Pokes of a certain color. How could I classify them like that? That was an interesting problem, and is the subject of my next post. […]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

The Space Quest Historian

Adventure game blogs, Let's Plays, live streams, and more

Harebrained Schemes

Developer's blog for IceFall Games

kosmonaut's blog

3d GFX and more

Halogenica

Turn up the rez!

bitsquid: development blog

Developer's blog for IceFall Games

Game Development by Sean

Developer's blog for IceFall Games

Lost Garden

Developer's blog for IceFall Games

Memories

Developer's blog for IceFall Games

Casey's Blog

Developer's blog for IceFall Games

Blog

Developer's blog for IceFall Games

Rendering Evolution

Developer's blog for IceFall Games

Simon schreibt.

Developer's blog for IceFall Games

Dev & Techno-phage

Do Computers Dream of Electric Developper?

- Woolfe -

Developer's blog for IceFall Games

Ferrara Fabio

Game & Application Developer, 3D Animator, Composer.

Clone of Duty: Stonehenge

First Person Shooter coming soon to the XBOX 360

Low Tide Productions

Games and other artsy stuff...

BadCorporateLogo

Just another WordPress.com site

Sipty's Writing

Take a look inside the mind of a game developer.

Jonas Kyratzes

Writer, game designer, filmmaker.

%d bloggers like this: