这将是一个很好的算法,将图像转换为一个规模有限的调色板 [英] What would be a good algorithm to convert an image to a limited size color palette

查看:137
本文介绍了这将是一个很好的算法,将图像转换为一个规模有限的调色板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找出一种算法,将转换的图像 - 8位或32位 - 为3或4自定义颜色有限的调色板(而不是灰度)

I am trying to figure out an algorithm that would convert an image - 8 or 32 bit - to a limited palette of 3 or 4 custom colors (not grayscale).

这可能吗?

我想用C ++(但我可以从其他语言得到它)

I am trying to use C++ (but I could get it from other languages)

看来,Qt的已经具备了调色板 - 虽然我并不了解它的用法,它似乎强制显示器上自己的标准调色板之一,我没有看到任何方式定制它

It seems that Qt already has a palette - though I don't understand its usage, it seems to force a display on one of its own standard palettes, I did not see any way of customizing it.

我会AP preciate一些算法的例子或建议。

I would appreciate some algorithm examples or suggestions.

推荐答案

您可以将图像转换为使用颜色固定的数量,通过传递QRgb值的数组与 convertToFormat

You can convert an image to use a fixed number of colors, by passing in an array of QRgb values with convertToFormat:

http://qt-project.org/doc/ QT-5 / qimage.html#convertToFormat-2

有没有在这种情况下,没有抖动......它只是挑选使用最接近的颜色。因此,这不是强迫你的手对调色板,但你必须决定使用什么颜色。有很多的,你可以看看,如果你要挑N最佳的颜色使用的图像在互联网上生成的从图像彩色调色板,虽然这将是一个启发。

There's no dithering in that case...it just picks the nearest color to use. So it's not forcing your hand about the palette, but you have to decide what colors to use. There are a lot of "color palette from image" generators on the Internet which you might look at if you want to pick the N "best" colors to use for an image, although it's going to be a heuristic.

如果你想抖动,你可能会从想从Meego的这种情况下,源启动:

And if you want dithering, you might start from sources like this case from Meego:

https://github.com/openwebos/qt/blob/master/src/plugins/graphicssystems/meego/dithering.cpp

通常人们用这样的任务将使用ImageMagick的:

Frequently people with tasks like this will use ImageMagick:

http://www.imagemagick.org/Usage/quantize/

这篇关于这将是一个很好的算法,将图像转换为一个规模有限的调色板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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