So I'm beginning to look into "simple" color reduction to apply to images. I've spent the last day researching how this works, and managed to find what seems to be a decent algorithm to experiment with here: Median cut algorithm
The output here is a palette of n colors. I have yet to ensure this algorithm actually works, but I'm assuming it does. What I would like to do is take that output and apply it to the image that the palette was generated from.
I can't say I'm well versed in color compression formats and all the deep knowledge when it comes to images, but I'm wondering how I can apply the palette without having to start with an image format that comes with an indexed palette (i.e. GIF).
I'm thinking that for each pixel, I calculate the difference between the color of the current pixel and each color in the palette, and replace that pixel with the palette color of the least difference. Would this be a viable way to approach?
Note - I have looked into various libraries (ImageMagick), but these seem slightly overkill; the most I'll be doing with image manipulation will be reducing the color palette - nothing more complex than this. That's why I'm thinking implementing this algorithm would be the simplest approach for my needs.