Python:将彩色标注图转变为灰度值标签图

import os
from PIL import Image
import cv2 as cv
import numpy as np

label_dir = './label/'
label_process_dir = './label_process/'
if not os.path.exists(label_process_dir):
    os.makedirs(label_process_dir)

for file in os.listdir(label_dir):
    label = label_dir + file
    if os.path.isfile(label):
        print(file)
        # 获得一张图片的所有种类的灰度值
        label_array = cv.imread(label, 0)
        print('label:', label_array.shape)
        class_image = np.unique(np.array(label_array))
        print('class_image:', class_image)

        for i in class_image:
            if i in [255, 106, 0]:  # 84, 111, 208,

                pass
            else:
                print('---------------------------------------------------------------')
                
        label_array[label_array == 0] =   1   #舌脉
        label_array[label_array == ]255 = 0   #背景
       # label_array[label_array == 106] = 2  
       # label_array[label_array == 84] = 2
       # label_array[label_array == 111] = 2
       # label_array[label_array == 208] = 2


        cv.imwrite(label_process_dir + file, label_array)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值