Image palette reduction

前端 未结 4 505
名媛妹妹
名媛妹妹 2020-12-08 11:32

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

4条回答
  •  星月不相逢
    2020-12-08 12:30

    This might be a little late to answer, but try this:

    1. make a set of each color in the image,
    2. sort them according to red, then green then blue (if preceding channels are equal), (they are now into a list)
    3. suppress nearby colors if they are too similar, ie distance in rgb space is smaller than 4.
    4. if they are still to much colors, suppress the least used ones.

    Each time you supress a color, you will have to add into a hash_map the colors and it's destination.

提交回复
热议问题