Monday, July 20, 2015

Reducing Color part III


Recently I found a few hours to pick my project of reducing colors in a color image. In my previous post I explained how I take a color image and let Matlab search for 12 colors (or any number of my choosing) that best represent the original. I was quite pleased with the result as it was, but there was still plenty of room for improvement. Letting the algorithm run longer was one of them.

One thing another that I thought was missing was naming the colors found. I am colorblind. For me it's sometimes hard to name green or orange. The author of XKCD once held an interesting experiment where he let people name colors. The results are interesting and funny. For me most important is the list with 954 named colors. I thought would be cool to see if I could first find the most dominant colors in an image and then find the name of that color (or something very close).

All the colors in the table were in Hex codes so I converted them with the help of a function I found on the Matlab File Exchange site.

Since my reduced color image only has 12 different RGB colors it's not too much effort to compare each of these values with the list of 954 colors. I took the Cartesian distance between two numbers.

I'm not sure if that is the best way of finding the right color name. We humans are pretty picky when it comes to colors. So a shade of gray shifted a bit darker will still look gray. But shift it in one direction (i.e. blue) and all of a sudden it's a color.


Two Shades of Gray


Gray and some Color

Ok, it's not a very distinct color, but it's not completely gray. Maybe you'd call it shadow blue or air force blue (people think of a lot of names).

Anyway I added the XKCD list to my algorithm and found colors close to the dominant colors and finally to see how well it worked I used those colors to paint the picture. Behold the three images: original photo, reduced colors and XKCD colors.
Original


Reduced to 12 colors

XKCD colors

And the colors are:
    'eggplant'
    'beige'
    'bubblegum pink'
    'piss yellow'
    'deep lilac'
    'brownish orange'
    'rusty red'
    'very light pink'
    'darkish pink'
    'brick red'
    'light burgundy'
    'dried blood'

I don't think the colors are an exact match. And my reducing colors algorithm still has varying results, but it sort of work.

If I ever learn how to make this into a smartphone app I can walk through the supermarket and I will finally be able to pick the yellow banana's (#ffff7e apparently).
Questions are always welcome.