EmguCV/OpenCV 图像加法/减法
我正在使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我将在这里发布我找到的答案,以防将来有人遇到同样的问题。
您将这样做:
来源: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:
Source: EmguCV's forums, here is the post that gave me the reply
请注意,有一个更清晰的语法:
Note that there is a cleaner syntax for that: