【代码调试】Camvid数据集:单通道转三通道

【代码调试】Camvid数据集:单通道转三通道

      • Camvid数据集单转三通道代码
      • 主函数内调用函数decode_segmap()代码
      • 独热图转三通道结果展示


Camvid数据集单转三通道代码

def decode_segmap(self, image):
	# Camvid数据集的标签及color
    sky = [128, 128, 128]
    building = [128, 0, 0]
    pole = [192, 192, 128]
    road_marking = [255, 69, 0]
    road = [128, 64, 128]
    pavement = [60, 40, 222]
    tree = [128, 128, 0]
    sign_symbol = [192, 128, 128]
    fence = [64, 64, 128]
    car = [64, 0, 128]
    pedestrian = [64, 64, 0]
    bicyclist = [0, 128, 192]
    label_colors = np.array([sky, building, pole, road_marking, road,
                            pavement, tree, sign_symbol, fence, car,
                            pedestrian, bicyclist]).astype(np.uint8)

    r = np.zeros_like(image).astype(np.uint8)
    g = np.zeros_like(image).astype(np.uint8)
    b = np.zeros_like(image).astype(np.uint8)

    for label in range(len(label_colors)):
            r[image == label] = label_colors[label, 0]
            g[image == label] = label_colors[label, 1]
            b[image == label] = label_colors[label, 2]

    rgb = np.zeros((image.shape[0], image.shape[1], 3)).astype(np.uint8)
    rgb[:, :, 0] = r
    rgb[:, :, 1] = g
    rgb[:, :, 2] = b
    return rgb

主函数内调用函数decode_segmap()代码

# main()函数内实现转变
if args.dataset == 'Camvid':
	for i in range(len(name)):                                # name为真实图像存储路径及名称
	    name_list = name[i].split('\\')
	    filename = os.path.join(args.save_dir, name_list[-1]) # 存储文件名获取
	    print(output.shape)                                   # (360, 480)
	    print(np.unique(np.array(output)))                    # 输出图像类别查看
	    out_img = test_dataset.decode_segmap(output)          # 输出结果图像的单通道转三通道实现
	    color_file = Image.fromarray(out_img, 'RGB')
	    print(out_img.shape)                                  # (360, 480, 3)
	    color_file.save(filename)

独热图转三通道结果展示

【代码调试】Camvid数据集:单通道转三通道_第1张图片


你可能感兴趣的:(深度学习,python,深度学习,图像处理)