views:

96

answers:

6

I'm trying to generate a color palette which has 16 colors. i will display this palette in 4x4 grid.

so i have to find a way to rgb color palette which has 255*255*255 colors divided to 16 colors equally and logically.

i think it's gonna be a mathematical algorithm. because i'm tring to pick 16 vectors from 3x3 matrix which picked in equal scale.

+2  A: 

You are basically projecting a cube (R X G X B) onto a square (4 X 4). First, I would start by asking myself what size cube fits inside that square.

1 X 1 X 1 =  1
2 X 2 X 2 =  8
3 X 3 X 3 = 27

The largest cube that fits in the square has 8 colors. At that point, I would note how conveniently 8 is an integral factor of 16.

I think the convenience would tempt me to use 8 basic colors in 2 variants like light and dark or saturated and unsaturated.

bbadour
+1 That's cheating ;)
aaronasterling
never mind. evenly distributing 8 elements is just as hard as 16.
aaronasterling
+2  A: 

A lot depends on what the colors are for. I you just want 16 somewhat arbitrary colors, I would suggest:

black    darkgray   lightgray white
darkred  darkgreen  darkblue  darkyellow
medred   medgreen   medblue   medyellow
lightred lightgreen lightblue lightyellow

I used that color set for a somewhat cartoonish-colored game (VGA) and found it worked pretty well. I think I sequenced the colors a little differently, but the sequence above would seem logical if arranged in a 4x4 square.

supercat
+3  A: 

You can approach this as a purely mathematical equipartition problem, but then it isn't really about color.

If you are trying to equipartition a color palette in a way that is meaningful to human perception, there are a large number of non-linearities that need to be taken into account which this article only mentions. For example, the colors #fffffe, #fffeff, and #feffff occupy far corners of the mathematical space, but are nearly indistinguishable to the human eye.

msw
the three colors you give as an example are clustered about the origin ;) point taken though.
aaronasterling
you're just numbering your axes backwards ;) point taken though.
msw
+2  A: 

When the number of selected colors (16) is so small (especially compared to the number of available colors), you'll much better off hand-picking the good-looking palette or using a standard one (like some pre-defined system or Web palette for 16 color systems) instead of trying to invent a mathematical algorithm for selecting the palette.

AndreyT
+1 I think this is the best solution. I've got the equipartition thing going on and it's ugly. just handpick them.
aaronasterling
yes i prefer to do that but actually i'm going to integrate this palette into a search logic, so i will choose a mathamatichal way
Mehmet Fatih Yıldız
A: 

This is a standard problem and known as color quantization. There are a couple of algorithms for this:

Objective: You basically want to make 16 clusters of your pixel in a 3 dimension space where the 3 axes varies from 0 to 255.

Methods are: 1) rounding of first significant bits. -- very easy to implement but does not give good result. 2) histogram method. - take median effort and give better result 3) quad tree. - state of the art data structure. Give best result but implementing the qaud tree data structure is hard.

There might be some more algorithms. But I have used these 3.

Atul
+2  A: 

actually i have found a way depends on this "dividing color palette" problem. i will use this color values with converting rgb values to hsv values.

hue, saturation, value

so i can use one integer value between 0-360 or i can use one integer between 0-100 (%) for my color palette.

finally, i can easily use this values for searhing/filtering my data based on color selection. i'm diving 0-360 range to 16 pices equally, so i can easily define 16 different colors.

but thanks for different approaches

Mehmet Fatih Yıldız
+1 self answers are good for StackOverflow
msw
but, as supercat suggested, you'll probably want to combine hue and value differences as either alone yield hard to distinguish items in 24-bit color.
msw