如何比较裁剪后的同源图像?

发布于 2024-10-15 09:19:12 字数 432 浏览 2 评论 0原文

假设我有一个图像文件/URL,并且我希望我的软件在最多 100 张图像(或至少按照这个数量级)的集合中搜索它。软件应该找到的目标图像应该是与给定图像“相同”的图像,但它仍然应该能够“原谅”对它们中的任何一个进行轻微的处理(这两个图像可能被不同地裁剪,或者它们被压缩)不同)。 问题是 - 鉴于在搜索发生之前我不会有任何图像(即,在搜索之前不会有任何索引),这是否是一项可行的任务。它是否可能在亚秒内工作时间(请记住,比较集非常小)。如果可行的话,我可以使用哪些工具来完成这项任务?这可以是软件组件,甚至可以是在线服务(我可以接受它作为概念证明)。 OpenSURF 可以帮助我吗? 为了进一步集中我的问题 - 我不是问要使用哪些算法,此时我宁愿使用现有的工具/API/服务。

Suppose I have an image file/URL, and I want my software to search it within a set of up to 100 images (or at least in that order of magnitude). The target image that the software should find should be the "same" image as the given image, but it should still be able to "forgive" slight processing on either of them (the two images may have been cropped differently, or they were compressed differently).
The question is - is this feasible a task, given that I won't have any of the images before the search is taking place (i.e., there won't be any indexing prior to the search.) Is it likely to work in subsecond time (remember that the compare set is quite small). And if feasible, which tools can I use for this task? This could be software components or even an online service (I can live with that for a proof of concept). Can OpenSURF help me here?
To focus my question further - I'm not asking which algorithms to use, at this point I would rather use an existing tool/API/service.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

嘦怹 2024-10-22 09:19:12

软件应该找到的目标图像应该与给定图像“相同”,但它仍然应该能够“原谅”对它们中的任何一个进行轻微的处理。

如果“轻微处理”不涉及旋转,而只涉及“裁剪”,那么简单的互相关应该可以工作,如果可以进行透视校正、旋转、镜头畸变校正,那么事情就更复杂了。

我认为这种方法对轻微的色彩校正相当宽容。无论如何,如果需要,您始终可以将两个图像转换为灰度并比较灰度版本。

为了进一步集中我的问题 - 我不是在问要使用哪些算法,此时我宁愿使用现有的工具/API/服务。

您可以从 OpenCV 库中的 cvMatchTemplate 开始(该链接指向 API 的 C 版本,但它也适用于 C++ 和 Python)。使用裁剪后的图像作为模板,并在所有图像中查找它。

如果您比较的图像在浅色背景上有深色特征,您可能会受益于使用 CV_TM_CCOEFFCV_TM_CCOEFF_NORMED 方法。他们都从两个图像中减去模板区域的平均值。标准化方法 (CV_TM_*_NORMED) 通常比非标准化方法效果更好,但速度较慢。

您可以考虑在互相关之前对图像进行一些预处理。如果您首先对它们进行归一化,互相关将对轻微的亮度/对比度修改不太敏感。如果按照@misha的建议首先检测边缘,您将丢失颜色/亮度信息,但轮廓重叠的结果会好得多。

The target image that the software should find should be the "same" image as the given image, but it should still be able to "forgive" slight processing on either of them.

If "slight processing" doesn't involve rotation, but only "cropping", then simple cross-correlation should work, if there could be perspective correction, rotation, lens distortion correction, then things are more complicated.

I think this method is quite forgiving to slight color corrections. Anyway, you can always convert both images to grayscale and compare grayscale versions if you want.

To focus my question further - I'm not asking which algorithms to use, at this point I would rather use an existing tool/API/service.

You can start from cvMatchTemplate from OpenCV library (the link points to the C version of the API, but it's available also for C++ and Python). Use the cropped image as a template, and look for it in all your images.

If the images you compare have dark features on light backgrounds, you may benefit from using CV_TM_CCOEFF or CV_TM_CCOEFF_NORMED methods. They both subtract the average over the template area from both images. Normalized methods (CV_TM_*_NORMED) generally work better but are slower than their non-normalized counterparts.

You may consider to do some preprocessing with the images before the cross-correlation. If you normalize them first, the cross-correlation will be less sensitive to slight brightness/contrast modification. If you detect edges first, as suggested by @misha, you'll lose color/lightness information, but the results for contour overlapping will be much better.

許願樹丅啲祈禱 2024-10-22 09:19:12

jetxee 让您走上正轨。但是,如果您仅使用模板匹配,则可能会遇到背景干扰模板匹配结果的问题。例如,如果您的模板是建筑物,并且您的背景主要是浅色(例如沙漠沙子),则模板匹配将会失败,因为较亮的背景始终会比较暗的模板返回更高的互相关性。这是此问题的示例

解决该问题的方法与链接中的方法相同:

  • 对模板和目标图像执行边缘检测。
  • 扔掉原始模板和图像
  • 使用边缘检测的模板和边缘检测的目标图像执行模板检测

只要允许轻微的处理,边缘检测步骤就会解决这个问题。只要两个图像中的边缘没有明显修改(模糊、光学扭曲),该方法就可以工作。

jetxee set you off on the right track. However, if you simply use template matching, you can run into problems where the background interferes with your template matching result. For example, if your template is a building and your background is primarily light (e.g. desert sand), then the template matching will fail because the lighter background will always return a higher cross-correlation than the darker template. Here is an example of this problem.

The way you solve it is the same as what is in the link:

  • Perform edge-detection on both your template and the target image.
  • Throw original template and image away
  • Perform template detection using the edge-detected template and edge-detected target image

As far as forgiving slight processing, the edge detection step will take care of that. As long as the edges in the two images are not modified significantly (blurred, optically distorted), the approach will work.

夜血缘 2024-10-22 09:19:12

我知道您并不是专门寻找算法,但尽管如此,让我建议以下内容,它可以非常有效地完成您想要做的事情...

对于同一图像的裁剪版本,包括旋转, Fourier-Mellin 变换对数极坐标变换(注意艺术半裸图 - 不过来源很好)会给您可以计算两幅图像之间的平移、旋转和缩放系数,从而确定从一幅图像到另一幅图像需要执行哪些操作。

I know you are not looking specifically for algorithms, but nonetheless, let me suggest the following which can accomplish exactly what you are trying to do, very efficiently...

For cropped versions of the same image, including rotation, the Fourier-Mellin transform or a log-polar transform (watch out for the artsy semi-nude drawing - good source however) will give you the translation, rotation and scale coefficients between the two images, allowing to to determine what operations were needed to go from one to the other.

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