I've got a predefined palette of 40-50 colors and a bunch of images. I need to get 3-4 dominant colors for each of them (exact match is not necessary - closest palette color is enough).
- I know there is no use checking full-sized image - 100x100px thumbnail is enough
- The only way I could think of is to make a histogram out of image's colors cast on palette, but since the palette is not spread evenly over sRGB color space you can't just reduce number of bits per color.
The simplest and most accurate way to cast it would be to treat each pixel's RGB values as coordinates in 3D space and find the closest point in palette, but for 40 palette colors and 100x100px image that would mean 40 x 100 x 100 = 400 000 times sqrt((x1-x2)+(y1-y2)2+(z1-z2)2) + as many value comparisons.
Do you know any way I could do it faster? Getting up to 5% wrong cast results would be acceptable.