使用Objective-C,有没有办法比较两个图像,并得到返回的%差值? [英] Using Objective-C, is there any way to compare two images and get a % difference value returned?

查看:110
本文介绍了使用Objective-C,有没有办法比较两个图像,并得到返回的%差值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Objective-C,有没有办法比较两个图像并返回%差值?

Using Objective-C, is there any way to compare two images and get a % difference value returned?

例如,一个图像将有和X。另一个图像将有一个X。第三个会有一个H。所有相同的字体/颜色。

For example, one image will have and X in it. Another image will have an X in it. And a third will have a H in it. All the same font/color.

显然,X和X的差异非常小。

Obviously the X and the X will have a % difference that is very small. The % between the X and the H would be very big.

我如何编写一个可以返回%差异的函数?

How would I write a function that can return me the % difference?

推荐答案

你将不得不仔细考虑你关心什么样的差异。

You are going to have to think quite carefully about what kind of differences you care about.

对相同大小的图像进行逐像素比较不会太难。

Doing a pixel-by-pixel comparison of identically sized images won't be too hard. Assign an error value to each pixel, and then somehow combine the differences to produce a single figure.

缩放一个或其他图片,如果他们开始不同的大小,但相同的方面比率也相当简单。

Scaling one or other image if they start off different sizes but the same aspect ratio is also fairly simple.

但是,边缘情况很快就会变得棘手。例如,如果你的两个X字符移位,那么一个在图像的左边,另一个在右边会发生什么?如果这些被检测为类似某种方式?

However, the edge cases get tricky very quickly. For example, what happens if your two X characters are displaced, so one is on the left of the image, and the other on the right? Should these be detected as "similar" somehow?

此外,当比较H和X,你想要一个高分 - 蝴蝶的图片?

Also, when comparing H to X, you want a high score - but how then would you rank an X against a colour picture of a butterfly? Even higher, presumably, but how much higher?

某种学习神经网络可能会帮助你,你在哪里找出什么样的价值观,你会分配给自己一些样本比较,然后训练网络返回您的示例图像的这些值。但是这对代码来说并不简单。

Some kind of learning neural network might help you, where you work out what values you would assign yourself to some sample comparisons, then train the network to return those values for your sample images. But that isn't trivial to code.

如果你的比较要求更简单 - 例如,你正在做某种类型的OCR,你知道你的输入可能是单色字符,那么你可以使用其他的技巧 - 但适当的技巧将取决于你想实现的目标。

If your comparison requirements are simpler - for example, you are doing some kind of OCR equivalent, and you know that your inputs are likely to be monochromatic characters, then there are other tricks you can use - but the appropriate ones will depend on what you are trying to achieve.

这篇关于使用Objective-C,有没有办法比较两个图像,并得到返回的%差值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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