简体   繁体   English

什么是将图像转换为有限尺寸调色板的好算法

[英]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.

相关问题 将调色板颜色的16x16真彩色图像转换为实际的调色板文件 - Convert 16x16 true-color image of palette colors, to actual palette file 将中值剪切颜色缩减算法的输出调色板应用于源图像 - Applying a Median Cut color reduction algorithm's output palette to the source image 空间有限的优先队列:寻找一个好的算法 - priority queue with limited space: looking for a good algorithm 查找与欧几里得距离以外的调色板算法最接近的颜色 - Find closest color to a palette algorithm other than Euclidian distance 什么是 iota_n 的良好实现(STL 中缺少算法) - What would be a good implementation of iota_n (missing algorithm from the STL) 是否有一个好的库或算法可以帮助将平面图像快速转换为交错图像(C ++)? - Is there a good library or algorithm that help convert planar image to interleaved image fast(C++)? 什么是存储颜色的好方法? - What is a good way to store color? 什么算法可以融合具有相同场景的多个图像,但每个图像中不同位置上的物体不同? - What algorithm would blend multiple images that has same scene except one object on different positions in every image? 什么是节流错误记录的良好“退避”算法? - What is a good “backoff” algorithm for throttling logging of errors? 王国防御的好算法是什么? - What's a good algorithm for Defense of a Kingdom?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM