像素色彩匹配估计
出于图像扫描的目的,我想要一个像素(可以从 UIImage 获取)与预设颜色匹配(按一定百分比)。
说粉色。当我扫描图像中的粉红色像素时,我想要一个函数返回像素中的 RGB 值与我预设的 RGB 值的相似程度的百分比。这样我希望所有(好吧,大多数)粉红色像素对我来说变得“可见”,而不仅仅是完全匹配。
有人熟悉这种方法吗?你会怎么做这样的事情?
提前致谢。
更新:感谢大家迄今为止的回答。我接受了 Damien Pollet 的答案,因为它进一步帮助了我,我得出的结论是,计算两种 RGB 颜色之间的矢量差对我来说非常适合(此时此刻)。随着时间的推移,它可能需要一些调整,但现在我使用以下内容(在目标 c 中):
float difference = pow( pow((red1 - red2), 2) + pow((green1 - green2), 2) + pow((blue1 - blue2), 2), 0.5 );
如果此差异低于 85,我接受该颜色作为我的目标颜色。由于我的算法不需要精度,所以我对这个解决方案很满意:)
更新2:在我搜索更多信息时,我发现以下网址,如果您正在寻找,它可能对您非常(轻描淡写)有用对于类似的东西。
http://www.sunsetlakesoftware.com /2010/10/22/gpu-accelerated-video-processing-mac-and-ios
For image scanning purposes, I'd like a pixel (which I can get from a UIImage) to match (for a certain percentage) to a pre-set color.
Say pink. When I scan the image for pixels that are pink, I want a function to return a percentage of how much the RGB value in the pixel looks like my pre-set RGB value. This way I'd like all (well, most) pink pixels to become 'visible' to me, not just exact matches.
Is anyone familiar with such an approach? How would you do something like this?
Thanks in advance.
UPDATE: thank you all for your answers so far. I accepted the answer from Damien Pollet because it helped me further and I came to the conclusion that calculating the vector difference between two RGB colors does it perfectly for me (at this moment). It might need some tweaking over time but for now I use the following (in objective c):
float difference = pow( pow((red1 - red2), 2) + pow((green1 - green2), 2) + pow((blue1 - blue2), 2), 0.5 );
If this difference is below 85, I accept the color as my target color. Since my algorithm needs no precision, I'm ok with this solution :)
UPDATE 2: on my search for more I found the following URL which might be quite (understatement) useful for you if you are looking for something similar.
http://www.sunsetlakesoftware.com/2010/10/22/gpu-accelerated-video-processing-mac-and-ios
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我想说,只需计算与目标颜色的矢量差,并检查其范数是否小于某个阈值。我怀疑某些 色彩空间 在这方面比其他色彩空间更好,可能是 HSL 或 L*ab,因为它们将亮度与色调本身分开,因此可能通过较小的颜色向量表示较小的感知差异...
另外,请参阅此相关问题
I would say just compute the vector difference to your target color, and check that it's norm is less than some threshold. I suspect some color spaces are better than others at this, maybe HSL or L*ab, since they separate the brightness from the color hue itself, and so might represent a small perceptual difference by a smaller color vector...
Also, see this related question
科学答案:您应该将两种颜色转换为 LAB 颜色空间并计算那里的欧几里得距离。该值也称为 deltaE。
LAB 空间的开发(使用测试人员)正是出于这个原因:以便在 tnis 空间中具有相等距离的不同颜色对对应于相等的感知颜色差异。
然而,听起来您并不是在寻找匹配特定的颜色,而是在寻找颜色范围(假设所有肤色)。这可能需要更多的用户输入,而不仅仅是参考颜色 + deltaE 容差:
具有 3 个色调、饱和度和亮度容差的参考颜色
参考颜色样本云
...
Scientific answer: You should convert both colors to the LAB color space and calculate the euclidian distance there. That value is also called deltaE.
The LAB space was developed (using test persons) for exactly that reaason: so that different color pairs with equal distances in tnis space correspond to equal perceived color differences.
However, it sounds like you are not looking for matching a specific color, but rather a color range (lets say all skin tones). That might require more user input than just a reference color + a deltaE tollerance:
a reference color with 3 tollerances for hue, saturation and brightness
a cloud of refence color samples
...