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

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.

主站蜘蛛池模板: 定襄县| 新田县| 平阴县| 田阳县| 聂拉木县| 大安市| 遵化市| 宜阳县| 崇明县| 江达县| 商丘市| 富川| 南江县| 抚顺市| 兴文县| 黑龙江省| 天祝| 渝中区| 筠连县| 崇信县| 龙陵县| 广水市| 成安县| 奉新县| 通许县| 靖西县| 南溪县| 冕宁县| 仁化县| 广元市| 宁晋县| 武隆县| 象州县| 渭源县| 广河县| 新野县| 西和县| 南岸区| 方正县| 思茅市| 柳河县|