2014-03-07 73 views

回答

5

基本:

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; 
      } 
     } 
    } 

希望我解决了你的问题。干杯(:做,如果你需要更多的帮助评论

12
inRange(src, lowerBound, upperBound, dst); 
bitwise_not(src, src); 
+2

FYI其他读者:http://docs.opencv.org/modules/core/doc/operations_on_arrays.html#inrange – rwong

+0

这个答案将帮助人们方式更多,如果你只是添加一些评论来解释每行是什么 –

+0

这可能是迟到的,但是在这种情况下,'bitwise_not'完成了什么?我尝试了Python中的第一行,它似乎做了无需任何其他工作。 – MLavrentyev

相关问题