EmguCV 阈值化

一、public static double cvThreshold(

      IntPtr src,

      IntPtr dst,

      double threshold,

      double maxValue,    //Maximum value to use with CV_THRESH_BINARY and CV_THRESH_BINARY_INV thresholding types

      Emgu.CV.CvEnum.THRESH thresholdType

  )

  thresholdType有如下几种:

  CV_THRESH_BINARY,表示dsti=(srci>T)?M:0。

  CV_THRESH_BINARY_INV,表示dsti=(srci>T)?0:M。

  CV_THRESH_TRUNC,表示dsti=(srci>T)?M:srci。

  CV_THRESH_TOZERO_INV,表示dsti=(srci>T)?0:srci。

  CV_THRESH_TOZERO,表示dsti=(srci>T)?srci:0。

  下图为不同类型的处理结果,第一副为原图:

     

   CV_THRESH_OTSU: use Otsu algorithm to choose the optimal threshold value; combine the flag with one of the above CV_THRESH_* values

二、public static void cvAdaptiveThreshold(

      IntPtr src,        //single-channel, 8-bit of 32-bit floating point

      IntPtr dst,

      double maxValue,    //Maximum value to use with CV_THRESH_BINARY and CV_THRESH_BINARY_INV thresholding types

      ADAPTIVE_THRESHOLD_TYPE adaptiveType,  //Adaptive method, CV_ADAPTIVE_THRESH_MEAN_C: indicates that Mean minus C; CV_ADAPTIVE_THRESH_GAUSSIAN_C: indicates that Gaussian minus C

      THRESH thresholdType,  //same with cvThreshold

      int blockSize=3,       //The size of a pixel neighborhood that is used to calculate a threshold value for the pixel: 3, 5, 7, ...

      double param1=5      //Constant subtracted from mean or weighted mean. It may be negative.

  )

  通过计算像素点周围的blockSize*blockSize区域的加权平均,然后减去param1来得到自适应阈值。CV_ADAPTIVE_THRESH_MEAN_C指对区域的所有象素平均加权;CV_ADAPTIVE_THRESH_GAUSSIAN_C指对区域内的像素根据高斯函数按照它们离中心点的距离进行加权计算。

 

posted @ 2014-01-18 10:59  胡炜  阅读(1041)  评论(0编辑  收藏  举报