Group the pixels into 5 buckets, take the average of the pixels in each bucket and then sort the colors based on the number of pixels in each bucket. Not sure what machine learning algorithm would be appropriate for classification but I don't think it would be that difficult. I'm pretty sure k-nearest neighbor would produce a decent classification if you think of pixels as being in a three dimensional space.
Then assign the color values into your CSS template, voila you should have a design that matches the color palette of each image.
edit: I've been playing with this process and just scaling the image to 16x16 seems to work fairly well for building a palette.
Group the pixels into 5 buckets, take the average of the pixels in each bucket and then sort the colors based on the number of pixels in each bucket. Not sure what machine learning algorithm would be appropriate for classification but I don't think it would be that difficult. I'm pretty sure k-nearest neighbor would produce a decent classification if you think of pixels as being in a three dimensional space.
Then assign the color values into your CSS template, voila you should have a design that matches the color palette of each image.
edit: I've been playing with this process and just scaling the image to 16x16 seems to work fairly well for building a palette.