EmguCV/OpenCV 图像加法/减法

发布于 2024-08-10 05:43:16 字数 888 浏览 11 评论 0原文

我正在使用 EmguCV 并尝试减去 2 个图像来创建类似于 AForge .NET 的 MoveTowards 过滤器。

这就是我从上面的 URL 中稍微修改的版本尝试做的事情。给定 2 个图像,源图像和覆盖图像 - 它会慢慢地将源图像移向覆盖图像。它基于以下内容执行此操作:

result = source + movementFactor * (overlay - source);

其中结果、源和覆盖是图像,而运动因子是 0 到 1 范围内的变化率。

当我在运动因子等于 1 的代码中尝试此操作时,结果看起来很混乱(有类似运动轨迹的东西)。为了进一步测试它,我从上面的等式中删除了movementFactor,并使结果=源+覆盖-源。我希望看到结果是叠加图像,我确实做到了,但图像的一个区域正在闪烁。

我猜测当进行加法/减法时,像素强度会被限制在上限或下限内。

我可以用这个完成我想要的:

for (int i = 0; i < src.Height; i++)
{
    for (int j = 0; j < src.Width; j++)
    {
        res[i, j] = new Gray(src[i, j].Intensity + movementFactor * (ovr[i, j].Intensity - src[i, j].Intensity));
    }
}

但这会显着减慢处理速度。如何克服上述加法/减法问题或速度问题?感谢您的回答!

I am using EmguCV and am trying to subtract 2 images to create a filter similar to AForge .NET's MoveTowards filter.

This is what my slightly modified version from the above URL tries to do. Given 2 images, the source and the overlay - it slowly moves the source image towards the overlay. It does this based on the following:

result = source + movementFactor * (overlay - source);

where result, source and overlay are images and movementFactor is the rate of change in the range 0 to 1.

When I tried this in code with movementFactor equal to 1, the results looked messed up (there was something like a motion trail). To test it further, I removed movementFactor from the above equation, and made result = source + overlay - source. I expected to see the overlay image as the result, which I did, but along with one region of the image that was flashing.

I am guessing that pixel intensities get clipped in the upper or lower bounds when addition/subtraction takes place.

I can accomplish what I want with this:

for (int i = 0; i < src.Height; i++)
{
    for (int j = 0; j < src.Width; j++)
    {
        res[i, j] = new Gray(src[i, j].Intensity + movementFactor * (ovr[i, j].Intensity - src[i, j].Intensity));
    }
}

But this significantly slows down the processing. How can I overcome the addition/subtraction problem or the speed problem with the above? Thanks for your answers!

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

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

发布评论

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

评论(2

ら栖息 2024-08-17 05:43:16

我将在这里发布我找到的答案,以防将来有人遇到同样的问题。

您将这样做:

Image<Gray,Byte> result = new Image<Gray,Byte>(source.Size);
CvInvoke.cvAddWeighted(source, 1.0-movementFactor, overlay, movementFactor, 0.0, result);

来源:EmguCV 论坛,这里是 帖子 给了我回复

I will post the answer I found over here, in case someone runs across the same issue in the future.

This is how you would do it:

Image<Gray,Byte> result = new Image<Gray,Byte>(source.Size);
CvInvoke.cvAddWeighted(source, 1.0-movementFactor, overlay, movementFactor, 0.0, result);

Source: EmguCV's forums, here is the post that gave me the reply

画▽骨i 2024-08-17 05:43:16

我会在这里发布我找到的答案,以防有人遇到
未来同样的问题。

您将这样做:

图像<灰度,字节>结果 = 新图像<灰度,字节>(source.Size);
CvInvoke.cvAddWeighted(源,1.0-movementFactor,覆盖,movementFactor,0.0,结果); 

来源:EmguCV 的论坛,这里是
给我回复的帖子

请注意,有一个更清晰的语法:

var result = frame.AddWeighted(1.0 - movementFactor, overlay, movementFactor, 0.0);

I will post the answer I found over here, in case someone runs across
the same issue in the future.

This is how you would do it:

Image<Gray,Byte> result = new Image<Gray,Byte>(source.Size);
CvInvoke.cvAddWeighted(source, 1.0-movementFactor, overlay, movementFactor, 0.0, result); 

Source: EmguCV's forums, here is the
post that gave me the reply

Note that there is a cleaner syntax for that:

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