如何使用getRGB在Java中匹配类似的颜色 [英] How to match similar colours in Java using getRGB

查看:629
本文介绍了如何使用getRGB在Java中匹配类似的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用机器人截取屏幕截图,然后在这些屏幕截图中搜索较小的图片。这在Windows上,但不是OS X,因为伽马校正。我可以想出的最佳解决方案是简单地匹配类似的颜色,而不是精确的颜色匹配。

I am taking screenshots of the screen using robot and then searching for smaller images within those screenshots. This works on Windows but not OS X because of gamma correction. The best solution I can come up with is to simply match similar colours instead of exact color matches.

我担心的是,匹配类似的颜色将意味着超越getRGB, (因为它需要多个屏幕截图,并将它们与较小的图片进行比较,以便快速搜索匹配)。

My fear is that matching similar colours will mean going beyond getRGB therefore will slow down my program (because it's taking multiple screenshots and comparing them to a smaller image to search for a match very quickly).

我的问题是,我说BufferedImage和BufferedImage smallImage,我将如何确定Screenshot.getRGB(1,1)和smallImage.getRGB(1,1)是否类似颜色?

My question is, lets say I had BufferedImage Screenshot and BufferedImage smallImage, how would I go about determining if Screenshot.getRGB(1,1) and smallImage.getRGB(1,1) are similar colours?

推荐答案

关于这个问题有一个有趣的文章:

There's an interesting paper on exactly this problem:

新的感知统一色彩空间基于内容的图片和视频检索的相似性度量由M. Sarifuddin和Rokia Missaoui提供

A New Perceptually Uniform Color Space with Associated Color Similarity Measure for Content-Based Image and Video Retrieval by M. Sarifuddin and Rokia Missaoui

这很容易使用Google或特别是 Google学术搜索

You can find this easily using Google or in particular Google Scholar.

总而言之,一些颜色空间(例如, RGB,HSV,Lab)和距离度量(例如几何平均和欧几里德距离)是人类对颜色相似性的感知的更好表示。本文讨论了一个新的颜色空间,这比其他颜色空间更好,但它也提供了常见的现有颜色空间和距离度量的一个很好的比较。定性*,似乎使用通常可用的颜色空间的感知距离的最佳测量是:HSV颜色空间和圆柱形距离测量。

To summarise, some color spaces (e.g. RGB, HSV, Lab) and distance measures (such as Geometric mean and Euclidean distance) are better representations of human perception of color similarity than others. The paper talks about a new color space, which is better than the rest, but it also provides a good comparison of the common existing color spaces and distance measures. Qualitatively*, it seems the best measure for perceptual distance using commonly available color spaces is : the HSV color space and a cylindrical distance measure.

*至少根据参考文件中的图15。

*At least, according to Figure 15 in the referenced paper.

圆柱距离测量是乳胶符号):

The cylindrical distance measure is (in Latex notation):

D_ {cyl} = \sqrt {\Delta V ^ {2} + S_1 ^ {2} + S_2 ^ {2} -2S_1S_2cos (\Delta H)}

D_{cyl} = \sqrt{\Delta V^{2}+S_1^{2}+S_2^{2}-2S_1S_2cos(\Delta H)}

另请注意,有一些类似的问题可解决同一问题:

Also note there are some similar questions that address the same issue:

以编程方式查找相似的颜色

< a href =http://stackoverflow.com/questions/1633828/distance-between-colours-in-php/1634206#1634206>距离

"Distance" between colours in PHP

最后,在Java中,有任何简单的方法可以将RGB值转换为其他颜色空间:

Finally, in Java, there's any easy way to convert from RGB values into other color spaces:

ColorSpace.fromRGB

这篇关于如何使用getRGB在Java中匹配类似的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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