图像比较
在视觉c中比较两个图像的有效方法是什么? 还必须以哪种格式存储图像。(bmp、gif、jpeg......)? 请提供一些建议
What is the efficient way to compare two images in visual c..?
Also in which format images has to be stored.(bmp, gif , jpeg.....)?
Please provide some suggestions
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
如果您尝试比较的图像具有您想要区分的独特特征,则 PCA 是一个很好的方法。您需要什么格式的文件的问题实际上是无关紧要的;您需要将其作为数字数组加载到程序中并进行分析。
If the images you are trying to compare have distinctive characteristics that you are trying to differentiate then PCA is an excellent way to go. The question of what format of the file you need is irrelevant really; you need to load it into the program as an array of numbers and do analysis.
你的问题在复杂性方面打开了一罐蠕虫。
如果您想比较两个图像以检查它们是否相同,那么您需要对文件执行 md5(删除可能会扭曲结果的元信息)。
如果您想比较它们是否看起来相同,那么这是一个完全不同的故事。 “看起来相同”的含义非常宽松(例如,它们是完全相同的图像,但以两种不同的文件格式存储)。为此,您需要先进的算法,这将为您提供两个图像相同的概率。作为该领域的专家,我会执行以下“凭空发明”的算法:
该算法应该对颜色漂移和图像旋转不敏感。也许还可以缩放(您可以根据该区域进行标准化)。但我重申:不是专家,可能有更好的,而且可能会让小猫哭泣。
Your question opens a can of worms in terms of complexity.
If you want to compare two images to check if they are the same, then you need to perform an md5 on the file (removing possible metainfos which could distort your result).
If you want to compare if they look the same, then it's a completely different story altogether. "Look the same" is intended in a very loose meaning (e.g. they are exactly the same image but stored with two different file formats). For this, you need advanced algorithms, which will give you a probability for two images to be the same. Not being an expert in the field, I would perform the following "invented out of my head" algorithm:
This algorithm should be insensitive to color drift and image rotation. Maybe also scaling (you normalize against the area). But I restate: not an expert, there's probably much better, and it could make kittens cry.
我做了类似的事情来检测 MJPEG 流中的运动,并仅在运动发生时记录图像。
对于每个解码图像,我使用以下方法与之前的图像进行比较。
然后只需调整两个阈值
即可使用 System.Drawing 进行比较。位图,但由于我的源图像是 jpg,因此存在一些伪影,
如果您要自己滚动它,这是比较图像差异的一种很好的简单方法。
I did something similar to detect movement from a MJPEG stream and record images only when movement occurs.
For each decoded image, I compared to the previous using the following method.
Then it was just a matter of tuning the two threshold values.
I did the comparisons using System.Drawing.Bitmap, but as my source images were jpg, there were some artifacting.
It's a nice simple way to compare images for differences if you're going to roll it yourself.
如果您想确定 2 个图像在感知上是否相同,我相信最好的方法是使用图像哈希算法。您可以计算两个图像的哈希值,并且可以使用哈希值来获得它们匹配程度的置信度。
我已经取得了一些成功的一个是 pHash,尽管我不知道它使用起来有多容易使用 Visual C。搜索“几何哈希”或“图像哈希”可能会有所帮助。
If you want to determine if 2 images are the same perceptually, I believe the best way to do it is using an Image Hashing algorithm. You'd compute the hash of both images and you'd be able to use the hashes to get a confidence rating of how much they match.
One that I've had some success with is pHash, though I don't know how easy it would be to use with Visual C. Searching for "Geometric Hashing" or "Image Hashing" might be helpful.
严格同一性测试很简单:只需将源图像 A 中的每个像素与图像 B 中相应的像素值进行比较。如果所有像素都相同,则图像是相同的。
但我想我不想要这种严格的身份。即使某些变换已应用于图像 B,您可能也希望图像“相同”。这些变换的示例可能是:
,例如打印图像并再次扫描可能包括以上所有内容。
简而言之,您必须决定要将哪些变换视为“相同”,然后找到对这些变换不变的图像度量。 (或者,您可以尝试恢复翻译,但如果转换从图像中删除信息,例如模糊或剪切图像,则这是不可能的)
Testing for strict identity is simple: Just compare every pixel in source image A to the corresponding pixel value in image B. If all pixels are identical, the images are identical.
But I guess don't want this kind of strict identity. You probably want images to be "identical" even if certain transformations have been applied to image B. Examples for these transformations might be:
e.g. printing an image and scanning it again would probably include all of the above.
In a nutshell, you have to decide which transformations you want to treat as "identical" and then find image measures that are invariant to those transformations. (Alternatively, you could try to revert the translations, but that's not possible if the transformation removes information from the image, like e.g. blurring or clipping the image)