图像调色板减少 [英] Image palette reduction

查看:177
本文介绍了图像调色板减少的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在玩电脑图形编程的第一次。我想RGB(24位)图像转换为索引调色板(8位)的图像(如GIF)。我最初的想法是使用k均值(其中k = 256)。

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).

如何将一去挑选最佳的调色板一个给定的形象?这是一个学习的经历对我来说,所以我会preFER概览式的答案源$ C ​​$ C。

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.

编辑:抖动目前是题外话。我只是指的是简单的色彩转换,心理视觉/感知模型待用;色彩空间也是目前题外话,虽然色彩空间之间移动的就是让我思考这个摆在首位:)

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 :)

推荐答案

编辑: 更新,可支持256色调色板

如果你需要最简​​单的方法,那么我会建议基于直方图的方式:

If you need simplest method then I would suggest histogram based approach:


Calculate histograms of R/G/B channels
Define 4 intensity ranges
For each channel in intensity range
  Split histogram into 4 equal parts
  For each histogram part
    Extract most frequent value of that part

现在你将有4 * 4 ^ 3 = 256种颜色的调色板。当指定像素的调色板色彩,才算像素的平均强度看你必须用什么强度区。之后,仅仅映射的那些64色强度区域中的一个像素值。

Now you will have 4*4^3=256 colors palette. When assigning pixel to palette color, just calculate average intensity of pixel to see what intensity region you must use. After that just map one of those 64 colors of intensity region to pixel value.

祝你好运。

这篇关于图像调色板减少的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆