当前位置: 移动技术网 > IT编程>脚本编程>Python > 计算机视觉(1)关于cvThreshold二值化函数

计算机视觉(1)关于cvThreshold二值化函数

2020年03月23日  | 移动技术网IT编程  | 我要评论

你的承诺简谱,我拥有我快乐 作文,詹妮弗劳伦斯凸点

计算机视觉(1)关于cvthreshold二值化函数

 

opencv中文说明中是这样说的:

threshold   

对数组元素进行固定阈值操作

void cvthreshold( const cvarr* src, cvarr* dst, double threshold, double max_value, int threshold_type );

src:原始数组 (单通道 , 8-bit of 32-bit 浮点数)。
dst:输出数组,必须与 src 的类型一致,或者为 8-bit。
threshold:阈值
max_value:使用 cv_thresh_binary 和 cv_thresh_binary_inv 的最大值。
threshold_type:阈值类型
threshold_type=cv_thresh_binary:如果 src(x,y)>threshold ,dst(x,y) = max_value; 否则,dst(x,y)=0;
threshold_type=cv_thresh_binary_inv:如果 src(x,y)>threshold,dst(x,y) = 0; 否则,dst(x,y) = max_value.
threshold_type=cv_thresh_trunc:如果 src(x,y)>threshold,dst(x,y) = max_value; 否则dst(x,y) = src(x,y).
threshold_type=cv_thresh_tozero:如果src(x,y)>threshold,dst(x,y) = src(x,y) ; 否则 dst(x,y) = 0。
threshold_type=cv_thresh_tozero_inv:如果 src(x,y)>threshold,dst(x,y) = 0 ; 否则dst(x,y) = src(x,y).
 

    # cv.thresh_otsu  整幅图像 自动测试阀值
    # 如果 src(x,y)>threshold ,dst(x,y) = max_value; 否则,dst(x,y)=0;
    ret1,thresh1=cv.threshold(grade,0,255,cv.thresh_binary|cv.thresh_otsu)
    # 如果 src(x,y)>threshold,dst(x,y) = 0; 否则,dst(x,y) = max_value.
    ret2,thresh2=cv.threshold(grade,0,255,cv.thresh_binary_inv|cv.thresh_otsu)
    # adaptivethreshold:自适应阈值二值化
    # dst = cv2.adaptivethreshold(src, maxval, thresh_type, type, block
    # size, c)
    #
    # src: 输入图,只能输入单通道图像,通常来说为灰度图
    # dst: 输出图
    # maxval: 当像素值超过了阈值(或者小于阈值,根据type来决定),所赋予的值
    # thresh_type: 阈值的计算方法,包含以下2种类型:cv2.adaptive_thresh_mean_c; cv2.adaptive_thresh_gaussian_c.
    # type:二值化操作的类型,与固定阈值函数相同,包含以下5种类型: cv2.thresh_binary; cv2.thresh_binary_inv; cv2.thresh_trunc; cv2.thresh_tozero;cv2.thresh_tozero_inv.
    # block
    # size: 图片中分块的大小
    # c :阈值计算方法中的常数项


    th1=cv.adaptivethreshold(grade,255,cv.adaptive_thresh_mean_c,cv.thresh_binary,11,3)
    th2=cv.adaptivethreshold(grade,255,cv.adaptive_thresh_gaussian_c,cv.thresh_binary,11,3)

 

 

 

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网