寻找图像上的斑点 - 数学方法? [英] Finding spot on an image - mathematical way?

查看:115
本文介绍了寻找图像上的斑点 - 数学方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在图像上找到预定义区域并将其替换为另一个图像(只需嵌入后者)。预定义的点将是一个可变大小的矩形区域,其中填充了先前约定颜色的纯色背景。

I need to find a predefined area on an image and replace it with the other image (by just embedding the latter). The predefined spot would be a variable size rectangle area filled with solid background of the previously agreed colour.

有关如何实现此目的的任何建议?

Any advise on how do I achieve this?

我想我可以通过循环逐行逐像素地找到指定颜色的第一个像素,但我觉得这不是最有效的解决方案。由于该地点应该相当大,我也考虑过了图片(请参阅下面的附件)。

I guess I can find a first pixel of the specified colour by doing a loop and going through the image row by row, pixel by pixel, but I feel like that's not the most efficient solution. Since the spot is supposed to be rather big, I also thought about going across the picture (please see the attachment below).

所以我需要帮助来定义这些循环。我相信我必须使用一些数学函数。

So I need help in defining those loops. I believe I'll have to use some mathematical functions for that.

例如,如果大图是方形,则对角线环(黄色 EF 线)将使用简化线性函数 y = x y = 1x + 0 ),但它不太可能是正方形。所以我将不得不使用扩展的完整线性函数 y = kx + b 其中 k 将有事情要做矩形大小(我认为 k =高度/宽度),而 b 将只为0.所以循环将如下所示:

For example, if the big picture was square, the diagonal loop (the yellow EF line) would use the simplified linear function y=x (y=1x+0), but it's not likely to really be square. So I'll have to use the extended full linear function y=kx+b where k will have something to do with the rectangle size (I thought k=height/width), and b will be just 0. So the loop will look like:

$k = 1080/1920;
for ( $x=1920; $x>0; $x-- ) {
    $y = $k*$x;
}

但那是黄色的,我猜是最简单的。现在,我该如何定义其他?请帮忙。谢谢

But thats the yellow one, and the most simple I guess. Now, how do I define the others? Please help. Thanks

推荐答案

获取您正在搜索的子图像,并在大图中搜索。

Get pieces of your sub-image you're searching and search it in the big image.

您可以使用ImageMagick的子图像搜索:

You can use ImageMagick's sub-image search:

compare -verbose -dissimilarity-threshold 0.1 -subimage-search subimage.jpg bigimage.jpg

了解更多关于此这里这里这里

它会告诉你TooDissimilar或它会告诉你子图像的x,y位置。

It will either tell you "TooDissimilar" or it will tell you the x,y position of the subimage.

这篇关于寻找图像上的斑点 - 数学方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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