当前位置:网站首页>Image binarization processing of opencv

Image binarization processing of opencv

2022-07-31 06:32:00 xp_fangfei

opencvBinarization operation is divided into:There are two types of global threshold and local threshold.The image needs to be grayscaled before image binarization.

全局阈值

The global threshold is divided into:There are two types of manual threshold and automatic threshold.

手动阈值
opencv函数:

threshold(gray_src, dst, threshold_value, threshold_max,THRESH_BINARY);
//原图,目标图,known threshold(Threshold for comparison),阈值最大值,阈值类型(threshold()函数支持的对图像取阈值的方法由其确定)

There are methods for this function to threshold the image5种:

  • THRESH_BINARY:过门限的值为最大值,其他值为0
    在这里插入图片描述

  • THRESH_BINARY_INV:过门限的值为0,其他值为最大值
    在这里插入图片描述

  • THRESH_TRUNC:过门限的值为门限值,其他值不变
    在这里插入图片描述

  • THRESH_TOZERO:过门限的值不变,其他设置为0
    在这里插入图片描述

  • THRESH_TOZERO_INV:过门限的值为0,其他不变
    在这里插入图片描述
    自动阈值
    Automatic thresholds are divided into大津法三角形算法两种:

  • 大津法
    opencv函数:
threshold(gray_src,dst,0,255,cv.THRESH_BINARY | cv.THRESH_OTSU)
  • 三角形算法
    opencv函数:
threshold(gray_src,dst,0,255,cv.THRESH_BINARY | cv.THRESH_TRIANGLE)

局部阈值(自适应阈值)

There are two methods for calculating the local threshold::mean_c 和 guassian_c

  • ADAPTIVE_THRESH_MEAN_C
    opencv函数:
adaptiveThreshold(gray_src, dst, 255, cv::ADAPTIVE_THRESH_MEAN_C, cv::THRESH_BINARY, 57, 5);
  • ADAPTIVE_THRESH_GAUSSIAN_C
    opencv函数:
adaptiveThreshold(gray_src, dst, cv.ADAPTIVE_THRESH_GAUSSIAN_C, cv.THRESH_BINARY, 25, 10)
原网站

版权声明
本文为[xp_fangfei]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/212/202207310515103684.html