Python converting an image to use less colors

后端 未结 2 794
無奈伤痛
無奈伤痛 2021-01-07 02:05

I want to take an image and (somehow) read it as an array of pixels. Meaning each element of the 2d array would be either a hex code or RGB 3-tuple that represent the color

2条回答
  •  执笔经年
    2021-01-07 02:58

    What you are after is called color quantization. Several algorihtms have been designed, such as the Median Cut or the Popularity algorithm. They allow you to build an "optimal" color table with the desired number of entries.

    These methods were popular in the times of expensive graphics cards, but have lost fame since the generalization of true color.

    Complementarily to color quantization, one often uses color dithering, a method that restores some of the smoothness of color gradients and avoids banding effects.

    https://nl.mathworks.com/help/images/reduce-the-number-of-colors-in-an-image.html?requestedDomain=true

提交回复
热议问题