OpenCV中最小值的阈值图像

问题描述 投票:0回答:2

我想使用cv::threshold函数,因为它经过了很好的优化,而不是自己遍历整个图像..但它没有阈值到最小值。可用的选项:

enter image description here

我想要的是将小于某个值的像素设置为该值,例如:

image.at<float>(j,i) > 0.1f ? image.at<float>(j,i): 0.1f;

我可以不使用循环吗?

我试过了:

image.setTo(0.1, image < 0.1);

但是它说:

 error: no match for ‘operator<’ (operand types are ‘const cv::UMat’ and ‘double’)

PS:我的图像是cv :: UMat类型

c++ opencv threshold
2个回答
1
投票

请注意,对于0到255之间的数字x,等价max(x, thresh) == 255 - min(255-x, 255-thresh)成立,结果保持在[0,255]之内。

因此,您可以(i)反转图像,(ii)通过255-thresh构建最大阈值,以及(iii)再次反转。

请注意,对于任何常数a,数学上它保持max(x, thresh) == a - min(a-x, a-thresh),例如max(x, thresh) == -min(-x, -thresh)。最后一个是浮点数据的首选。


1
投票

我找到了这个功能:

void cv::max(
const Mat& src1, // Input array
double value, // Scalar input
Mat& dst // Result array
); 

它将src1的每个元素与value进行比较并取最大值,它具有阈值但具有cv::max函数。

© www.soinside.com 2019 - 2024. All rights reserved.