图像比较

发布于 2024-08-02 10:33:54 字数 70 浏览 5 评论 0原文

在视觉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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

夏天碎花小短裙 2024-08-09 10:33:54

如果您尝试比较的图像具有您想要区分的独特特征,则 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.

∝单色的世界 2024-08-09 10:33:54

你的问题在复杂性方面打开了一罐蠕虫。

如果您想比较两个图像以检查它们是否相同,那么您需要对文件执行 md5(删除可能会扭曲结果的元信息)。

如果您想比较它们是否看起来相同,那么这是一个完全不同的故事。 “看起来相同”的含义非常宽松(例如,它们是完全相同的图像,但以两种不同的文件格式存储)。为此,您需要先进的算法,这将为您提供两个图像相同的概率。作为该领域的专家,我会执行以下“凭空发明”的算法:

  • 从图像中获取任意一组像素点。
  • 对于每个像素,从颜色接近的周围像素中“生长”出一个多边形(根据 HSV 颜色空间)
  • 对另一个图像执行相同操作
  • 对于一个图像的每个多边形,检查与另一个图像中所有其他多边形的几何相似性图像,并选择最高值。将该值除以多边形的面积(以标准化)。
  • 根据获得的最高值创建一个向量,
  • 该向量的范数越高,两个图像相同的机会就越高。

该算法应该对颜色漂移和图像旋转不敏感。也许还可以缩放(您可以根据该区域进行标准化)。但我重申:不是专家,可能有更好的,而且可能会让小猫哭泣。

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:

  • take an arbitrary set of pixel points from the image.
  • for each pixel "grow" a polygon out of the surrounding pixels which are near in color (according to HSV colorspace)
  • do the same for the other image
  • for each polygon of one image, check the geometrical similitude with all the other polygons in the other image, and pick the highest value. Divide this value by the area of the polygon (to normalize).
  • create a vector out of the highest values obtained
  • the higher is the norm of this vector, the higher is the chance that the two images are the same.

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.

国际总奸 2024-08-09 10:33:54

我做了类似的事情来检测 MJPEG 流中的运动,并仅在运动发生时记录图像。

对于每个解码图像,我使用以下方法与之前的图像进行比较。

  • 将图像大小调整为有效的缩略图大小(我将相当高分辨率的图像调整为十倍)
  • 将每个像素的亮度与前一个图像进行比较,并标记它是否更亮或更暗(阈值1)
  • 一旦完成对于每个像素,您可以使用不同像素的计数来确定图像是否相同或不同(阈值 2)

然后只需调整两个阈值

即可使用 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.

  • Resize the image to effectively thumbnail size (I resized fairly hi-res images down by a factor of ten
  • Compare the brightness of each pixel to the previous image and flag if it is much lighter or darker (threshold value 1)
  • Once you've done that for each pixel, you can use the count of different pixels to determine whether the image is the same or different (threshold value 2)

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.

云淡风轻 2024-08-09 10:33:54

如果您想确定 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.

长途伴 2024-08-09 10:33:54

严格同一性测试很简单:只需将源图像 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:

  • changing image brightness globally (for every pixel)
  • changing image brightness locally (for every pixel in a certain area)
  • changing image saturation golbally or locally
  • gamma correction
  • applying some kind of filter to the image (e.g. blurring, sharpening)
  • changing the size of the image
  • rotation

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)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文