【发布时间】:2014-03-07 02:22:03
【问题描述】:
我喜欢在最大值和最小值范围内对图像进行阈值处理,并为超出该范围的像素值填充 255。我在 OpenCV 文档 here 中找不到这样的阈值。 谢谢
【问题讨论】:
标签: opencv
我喜欢在最大值和最小值范围内对图像进行阈值处理,并为超出该范围的像素值填充 255。我在 OpenCV 文档 here 中找不到这样的阈值。 谢谢
【问题讨论】:
标签: opencv
inRange(src, lowerBound, upperBound, dst);
bitwise_not(src, src);
【讨论】:
bitwise_not 究竟完成了什么?我只尝试了 Python 中的第一行,它似乎不需要其他任何东西就可以完成这项工作。
基本的:
threshold(src, dst, threshold value, max value, threshold type);
在哪里
src_gray: Our input image
dst: Destination (output) image
threshold_value: The thresh value with respect to which the thresholding operation is made
max_BINARY_value: The value used with the Binary thresholding operations (to set the chosen pixels)
threshold_type: One of the 5 thresholding operations.
例如,
threshold(image, fImage, 125, 255, cv::THRESH_BINARY);
表示低于 125 的每个值都将设置为零,高于 125 的值将设置为 255。
如果您要查找特定范围,例如 50 到 150,我建议您执行 for 循环,并自己检查和编辑像素。这很简单。看看我的这个 c++ 代码:
for (int i=0; i< image.rows; i++)
{
for (int j=0; j< image.cols; j++)
{
int editValue=image.at<uchar>(i,j);
if((editValue>50)&&(editValue<150)) //check whether value is within range.
{
image.at<uchar>(i,j)=255;
}
else
{
image.at<uchar>(i,j)=0;
}
}
}
希望我解决了您的问题。干杯(:如果您需要更多帮助,请发表评论。
【讨论】: