OpenCV 中的差异图像
如果我有图像数据 imgA
和 imgB
,那么我想计算 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用 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!
使用较新的 C++ 风格
cv::Mat
结构,您可以直接在矩阵上进行简单的算术运算。或者可以使用减法函数,请参阅此处。
With the newer C++ style
cv::Mat
structure you can do simple arithmetic such as this on the matrices directly.Alternatively the subtract function may be of use, see here.