官术网_书友最值得收藏!

Thresholding

After removing the background, we only have to binarize the image for future segmentation. We are going to do this with threshold. Threshold is a simple function that sets each pixel's values to a maximum value (255, for example). If the pixel's value is greater than the threshold value or if the pixel's value is lower than the threshold value, it will be set to a minimum (0):

Now, we are going to apply the threshold function using two different threshold values: we will use a 30 threshold value when we remove the light/background because all non-interesting regions are black. This is because we apply background removal. We will also a medium value threshold (140) when we do not use a light removal method, because we have a white background. This last option is used to allow us to check the results with and without background removal:

  // Binarize image for segment 
  Mat img_thr; 
  if(method_light!=2){ 
   threshold(img_no_light, img_thr, 30, 255, THRESH_BINARY); 
  }else{ 
   threshold(img_no_light, img_thr, 140, 255, THRESH_BINARY_INV); 
  } 

Now, we are going to continue with the most important part of our application: the segmentation. We are going to use two different approaches or algorithms here: connected components and find contours.

主站蜘蛛池模板: 时尚| 桃江县| 义马市| 舟曲县| 河津市| 当雄县| 林周县| 周口市| 虞城县| 乌拉特中旗| 海伦市| 涿州市| 岳西县| 东辽县| 河池市| 新闻| 江都市| 康乐县| 瓦房店市| 伊宁县| 合肥市| 堆龙德庆县| 浦江县| 宜昌市| 海盐县| 石门县| 章丘市| 永年县| 瓦房店市| 平定县| 太原市| 军事| 陵水| 延吉市| 汶川县| 温宿县| 敖汉旗| 红桥区| 库尔勒市| 尤溪县| 平遥县|