Objective-C中的图像/颜色比较 [英] Image/Color Comparison in Objective-C

查看:200
本文介绍了Objective-C中的图像/颜色比较的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找到一种比较两个图像的方法。让我给你一个例子,让你可以更好地理解:我的应用程序将随机化一个颜色(她将随机化一个值从0到255的R,然后为G,然后为B,结果是一个完全随机的RGB颜色)。
现在用户将从iPhone的相机拍照,应用程序将comprare的颜色与图像。
示例:应用程序选择RGB = 205,133,63是棕色:用户将拍摄一张桌子的棕色细节的图片。现在我需要比较iPhone选择的棕色和图片的棕色,并显示结果(例如:图片忠实于88%与给定的颜色相比)。
我在互联网上找到这个例子,但我可以弄清楚如何在我的应用程序中实现这个: http://www.youtube.com/watch?v=hWRPn7IsChI

I'm trying to find a way to compare two images. Let me give you an example so you can better understand: my App will randomize a color (she will randomize a value from 0 to 255 for the R, then for the G and then for the B and the result is a completely random RGB color). Now the user will take a photo from the camera of the iPhone and the App will comprare the color with the image. Example: The App select the RGB = 205,133,63 wich is brown: the user will take a picture of a brown detail of a desk. Now I need to compare the brown selected by the iPhone and the brown of the picture and display a result (for example: "the pictures is faithful to 88% compared to the given color"). I found this example in internet, but I can figure out how I can implement this in my App: http://www.youtube.com/watch?v=hWRPn7IsChI

谢谢!

Marco

推荐答案

有很多方法可以做到这一点。如果你想保持简单,你可以平均你的整个图像的颜色。为了简单起见,我们假设你的图像只有两个像素:
RGB0 = 255,0,0(红色)
RGB1 = 0,0,0(黑色)

There are plenty of ways you can do this. If you want to keep it simple, you can average the colours for your entire image. For the sake of simplicity, let's say your image only has two pixels: RGB0 = 255, 0, 0 (red) RGB1 = 0, 0, 0 (black)

两者之间的平均值为
RGB_AVG = 128,0,0(暗红色)

Average between the two will be RGB_AVG = 128, 0, 0 (dark red)

现在可以计算差值在这个平均值和所选择的颜色205,133,63之间。这也可以以许多不同的方式做。这是一个:

Now you can calculate the difference between this average and the selected colour 205, 133, 63. This too you can do in many different ways. Here is one:

R = 205 - 128 = 80 
G = 133 - 0 = 133
B = 63 - 0 = 63
Total = 80 + 133 + 63 = 276

Total score = (756 - 276) / 756 = 63.5%

这只是一种方法,你可以收集字典中的所有颜色,并计数它们,如果你需要它是超级准确。这一切都取决于你想达到的目标。

This is just one way, you could collect all colours in a dictionary and count them if you need it to be super accurate. It all depends on what you want to achieve.

Btw:如果你的数字高于你的样本颜色,那么你的数字不会更高。使用ABS或任何你想要的方法。以上只是一个例子。

Btw: Reassure your numbers don't end up being higher if they are higher than your sample color. Use ABS or whatever method you want. The above is just an example.

这篇关于Objective-C中的图像/颜色比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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