I am playing with computer graphics programming for the first time. I want to convert RGB (24-bit) images to indexed-palette (8-bit) images (like GIF). My initial thought is to use k-means (with k=256).
How would one go about picking the optimal palette for a given image? This is a learning experience for me, so I would prefer an overview-type answer to source code.
Edit: Dithering is currently off-topic. I am only referring to "simple" color conversion, psycho-visual/perceptual models aside; color-space is also currently off-topic, though moving between color-spaces is what got me thinking about this in the first place :)
The method of color reduction is very simple: every color of the original picture is replaced by an appropriate color from the limited palette that is accessible. Unfortunately, the resulting image can become discolored and less attractive.
An image palette is a collection of colors that an image uses — similar to a painter's palette. An image palette is a subset of all the colors your monitor can display. Not all images have image palettes — only images with color depths between 16 and 256 colors have palettes that you can fine-tune and edit.
You can use "posterize" option on the Image menu and define the number of colors. In the case you mention, its bases on grayscale, so converting your (color) image to grayscale and then posterize it to the selectable amount of colors will do it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With