使用一个图像阈值另一个

Use one image to threshold another

我需要以一种非常具体的方式对图像应用阈值,所以我来这里看看是否可行。

假设我有两张图像:一张源图像和一张阈值图像。我想要的是获取源图像并使用阈值图像对其进行过滤。该操作会将源图像的每个像素与阈值图像进行比较。如果像素的亮度相同或更高,它会将其设置为白色。如果像素小于亮度,它会将其设置为黑色。

下面是阈值图像的示例:

如果我能澄清一下,请告诉我。

谢谢!

一个简单的 matrix expression 就可以完成这里的工作。

This is a list of implemented matrix operations that can be combined in arbitrary complex expressions (here A, B stand for matrices (Mat), s for a scalar (Scalar), alpha for a real-valued scalar (double)):

...

Comparison: A cmpop B, A cmpop alpha, alpha cmpop A, where cmpop is one of: >, >=, ==, !=, <=, <. The result of comparison is an 8-bit single channel mask whose elements are set to 255 (if the particular element or pair of elements satisfy the condition) or 0.

因此,像下面一行这样简单的事情就可以满足您的要求:

cv::Mat result(source >= threshold);