OpenCV 中的差异图像

发布于 2024-12-29 03:44:07 字数 493 浏览 0 评论 0原文

如果我有图像数据 imgAimgB,那么我想计算 imgC 如下:

for (int i = 0; i < numPixelsInA; i++) {
    imgC[i] = max(0, imgA[i]-imgB[i]);
}

我看不出有什么办法可以做到这一点openCV 无需编写本质上与上面类似的代码。很好奇我是否遗漏了一些东西。

作为对上述内容的警告,imgA 和 imgB 是 OpenCV uchar,因此,要真正使上述工作正常进行,该行必须替换为:

imgC[i] = (uchar) max(0, ((int) imgA[i]) - ((int) imgB[i]));

这就是为什么 OpenCV 实现对我更有吸引力,因为它们处理这些饱和问题正确地,如果/当我们获得 IPP 时,我们可以“免费”获得适当的加速。

If I have image data imgA and imgB, then I'd like to compute imgC as follows:

for (int i = 0; i < numPixelsInA; i++) {
    imgC[i] = max(0, imgA[i]-imgB[i]);
}

I can see no way to do this in openCV without writing code that is essentially like the above. Curious if I'm missing something.

As a caveat to the above, imgA and imgB are OpenCV uchar, and so, to really make the above work, the line has to be replaced with:

imgC[i] = (uchar) max(0, ((int) imgA[i]) - ((int) imgB[i]));

This is why an OpenCV implementation is more appealing to me, as they handle these saturation issues properly, and if/when we get IPP we can get the appropriate speed ups "for free."

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

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

发布评论

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

评论(2

樱花细雨 2025-01-05 03:44:08

您可以使用 compare 的组合来创建掩码,然后添加/减去仅对具有掩码集的像素进行操作 - 但我会按照您的方式进行操作!

You could use a combination of compare to create a mask and then add/subtract to only operate on pixels with the mask set - but I would just do it the way you are doing it!

我恋#小黄人 2025-01-05 03:44:07

使用较新的 C++ 风格 cv::Mat 结构,您可以直接在矩阵上进行简单的算术运算。

cv::Mat A, B, C;
A = getImageA();
B = getImageB();

C = A - B;

或者可以使用减法函数,请参阅此处

With the newer C++ style cv::Mat structure you can do simple arithmetic such as this on the matrices directly.

cv::Mat A, B, C;
A = getImageA();
B = getImageB();

C = A - B;

Alternatively the subtract function may be of use, see here.

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