[英]Setting every pixel in image to closest match from a list of Colors
How can I set the colour of every pixel in a image to it's closest colour match from a list of colours in RGB format (no alpha), that can be of any length, in C#? 如何在C#中将图像中每个像素的颜色设置为与RGB格式的颜色列表中最接近的颜色匹配(无Alpha),该颜色可以是任意长度?
It's basically creating a custom BitmapPalette, but since you can't do that (Trust me, I've tried everything possible for that), I need an alternative. 它基本上是在创建自定义BitmapPalette,但是由于您无法做到这一点(请相信我,我已经尝试了所有可能的方法),因此我需要一种替代方法。
Does anyone know a way to do this? 有人知道这样做的方法吗?
Boy...I hope you loves your maths... 男孩...我希望你喜欢数学...
This is a tough question. 这是一个棘手的问题。 To determine the "closeness of fit" between two colors, you first must understand the color space/color model in which your are working.
要确定两种颜色之间的“贴合度”,您首先必须了解工作所在的颜色空间/颜色模型。 The RGB color model (not counting the alpha channel) is essentially Euclidean in nature: each color maps to a point in 3D space.
RGB颜色模型(不计算alpha通道)本质上本质上是欧几里得:每种颜色都映射到3D空间中的一个点。 Ergo, the putative distance between two colors, C1 and C2 is
因此,两个颜色C1和C2之间的假定距离为
Distance = SQRT( (C1 red - C2 red ) 2 + (C1 green - C2 green ) 2 + (C1 blue - C2 blue ) 2 )距离= SQRT((C1 红色 -C2 红色 ) 2 +(C1 绿色 -C2 绿色 ) 2 +(C1 蓝色 -C2 蓝色 ) 2 )
WRT "normal" human visual perception, this is not necessarily correct. WRT“正常”人类的视觉感知,这不一定是正确的。 To take that into account gets much more complicated.
考虑到这一点变得更加复杂。
Try these two papers as jumping-off points: 尝试以下两篇文章作为起点:
The Color FAQ also provide many links to other colorspace resource s. 颜色常见问题解答还提供了许多指向其他颜色空间资源的链接 。
Some more links at http://www.golden-gryphon.com/software/misc/color-links.html http://www.golden-gryphon.com/software/misc/color-links.html上的更多链接
Here's a paper on color differences that might help also: http://www.axiphos.com/Reports/ColorDifferences.pdf 这是一篇有关色差的论文,也可能会有所帮助: http : //www.axiphos.com/Reports/ColorDifferences.pdf
Bruce Lindbloom's web site has lots of stuff as well, including a color difference calculator, that works in the CIE color space (which has provision for distance computations). 布鲁斯·林德布洛姆(Bruce Lindbloom)的网站上还有很多东西,包括一个色差计算器,该计算器可以在CIE色彩空间(可以进行距离计算)中使用。
ColorMine is open source C# library that has methods for converting between color spaces and comparing via a couple delta-e methods ColorMine是开放源代码C#库,它具有在色彩空间之间进行转换并通过几种delta-e方法进行比较的方法
For example, this will give you a similarity score based on the most common delta-E method (Cie76) 例如,这将为您提供基于最常见的delta-E方法(Cie76)的相似度得分
var a = new Rgb { R = 23, G = 117, B = 114 }
var b = new Rgb { R = 113, G = 27, B = 11 }
var deltaE = a.Compare(b,new Cie1976Comparison());
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.