I am building a program that converts an image into a cross stitch or mosaic pattern of coloured squares. The problem is that in sampling from the actual image the coloured squares that are produced can be of over a thousand colours. What I would like to be able to do is find similar colours and group then as one colour in order to reduce the number of colours required by a cross stitcher or mosaic maker. Any suggestions as to how to group similar colours would be appreciated.
One method of “similar” colors is Distance Tolerance (for which there are dozens if not hundreds of ways to do it)
basically you measure the distance (either RGB or HSV) between the two colors and if the distance is small enough they are “similar”
d=sqrt((c1.red-c2.red)^2+(c1.green-c2.green)^2+(c1.blue-c2.blue)^2)
Have you checked Google for algorithms on posterization?
My NeuroQuant class does posterization. It’s setup to take a true color Picture and produce a small set of colors that’ll best fit as replacements.
http://home.comcast.net/~trochoid/code/NeuroQuant4d.zip
It sounds though like you’ve already processed the Picture to make coloured squares and it might be better/easier to just pass in an array of Colors if that’s what you already have. Peeking at the source that should be an easy change, but some other lines I saw make me unsure how the algorithm will perform with small color inputs.
If this would work for you this is how it would…
//constuct with source Picture (or Color array)
dim nq As new NeuroQuant(myPicture)
//compute colorCount best fit colors for input
nq.buildColorMap(colorCount, quality)
//then either get an array of the colorCount Colors
dim reducedSet() As Color = nq.xtraGetColorList
//or go through your coloured squares and retrieve from the map
dim reducedColor As Color = nq.xtraConvertColor(myColouredSquare.colour)
Thanks folks! Now I can proceed.