美文网首页
14、超大图像二值化方法

14、超大图像二值化方法

作者: BigBigGuy | 来源:发表于2019-01-06 11:52 被阅读0次

    分块全局阈值

    def big_image_binary(image):
        '''
            超大图像二值化:
                cw = ch = 256:表示分成一块块256长的正方形   
        '''
        cw = 256
        ch = 256
        h, w = image.shape[:2]
    
        gray = cv.cvtColor(image, cv.COLOR_BGR2GRAY)
        for row in range(0, h, ch):  # 0~h,步长为256
            for col in range(0, w, cw):  # 0~h,步长为256
                roi = gray[row:row+ch, col:col+cw]  # roi区域
                ret, dst = cv.threshold(
                    roi, 0, 255, cv.THRESH_BINARY | cv.THRESH_OTSU)
                gray[row:row+ch, col:col+cw] = dst
                print(np.std(dst), np.mean(dst))  # std:方差,mean:均值
        cv.imwrite("./BigBinary.jpg", gray)
    
    全局分块,显然效果不是特别好

    分块局部阈值

     roi = gray[row:row+ch, col:col+cw]  # roi区域
     dst = cv.adaptiveThreshold(roi, 255, cv.ADAPTIVE_THRESH_GAUSSIAN_C, cv.THRESH_BINARY, 127, 10)
     gray[row:row+ch, col:col+cw] = ds
    
    高斯自适应阈值

    相关文章

      网友评论

          本文标题:14、超大图像二值化方法

          本文链接:https://www.haomeiwen.com/subject/recjrqtx.html