[英]What would be a good algorithm to convert an image to a limited size color palette
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). 我试图找出一种算法,可以将图像(8位或32位)转换为3或4种自定义颜色(不是灰度)的有限调色板。
Is this possible ? 这可能吗 ?
I am trying to use C++ (but I could get it from other languages) 我正在尝试使用C ++(但是我可以从其他语言获得它)
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. Qt似乎已经有了一个调色板-尽管我不了解它的用法,但它似乎强制在其自己的标准调色板上显示,我看不到任何自定义方法。
I would appreciate some algorithm examples or suggestions. 我将不胜感激一些算法示例或建议。
You can convert an image to use a fixed number of colors, by passing in an array of QRgb values with convertToFormat
: 通过使用
convertToFormat
传入QRgb值数组,可以将图像转换为使用固定数量的颜色:
http://qt-project.org/doc/qt-5/qimage.html#convertToFormat-2 http://qt-project.org/doc/qt-5/qimage.html#convertToFormat-2
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.
互联网上有很多“图像的调色板”生成器,如果您想选择N种“最佳”颜色用于图像,则可以查看这些生成器,尽管这将是一种启发式方法。
And if you want dithering, you might start from sources like this case from Meego: 而且,如果您希望抖动,则可以从Meego的这种情况开始:
https://github.com/openwebos/qt/blob/master/src/plugins/graphicssystems/meego/dithering.cpp https://github.com/openwebos/qt/blob/master/src/plugins/graphicssystems/meego/dithering.cpp
Frequently people with tasks like this will use ImageMagick: 通常具有以下任务的人会使用ImageMagick:
http://www.imagemagick.org/Usage/quantize/ http://www.imagemagick.org/用法/ quantize /
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.