当前位置 博文首页 > 图像通道的分离合并操作_Gentleman_ZH:PIL

    图像通道的分离合并操作_Gentleman_ZH:PIL

    作者:[db:作者] 时间:2021-09-02 16:26

    def Binarization():
    
        img = Image.open("1.png")
        r, g, b = img.split()  # 分离三通道
        # pic = Image.merge('RGB', (r, g, b))  # 合并三通道
    
        limg = img.convert('L') # 转换成单通道的灰度图
    
        threshold = 4
        table = []
        for i in range(256):
            if i < threshold:
                table.append(0)
            else:
                table.append(1)
    
        bimg = limg.point(table, "1") # 二值化,自定义阀值写入table
    
        bimg_L = bimg.convert('L') # 将二值化后的图像转化成灰度图才能拼接
    
        bimg_3 = Image.merge('RGB', (bimg_L, bimg_L, bimg_L)) # 将二值化图像拼接成三通道
    
        plt.imshow(bimg_3)
        plt.show()
    
        bimg.save("2.jpg")
    
        im = np.array(img)
        print(im.shape)

    ?

    cs