Muyun99's wiki Muyun99's wiki
首页
学术搬砖
学习笔记
生活杂谈
wiki搬运
资源收藏
关于
  • 分类
  • 标签
  • 归档
GitHub (opens new window)

Muyun99

努力成为一个善良的人
首页
学术搬砖
学习笔记
生活杂谈
wiki搬运
资源收藏
关于
  • 分类
  • 标签
  • 归档
GitHub (opens new window)
  • 代码实践-目标检测

  • 代码实践-图像分割

    • 基于深度学习的图像分割技术
    • 领域自适应
    • 如何计算一个模型的FPS,Params,GFLOPs
    • 常见数据集的相关知识
    • 如何加载数据集
    • 半监督与弱监督图像分割
    • PASCAL VOC 2012调色板 color map生成源代码分析
    • 语义分割数据集灰度分割图转彩色分割图代码
    • 复现PSA
    • 转换cityscapes 到对应的类别
    • 上采样函数
    • DeepLab系列代码
    • mIoU的计算
    • Multi-label 分类中如何计算 mAP
  • 代码实践-自监督学习

  • 竞赛笔记-视觉竞赛

  • 框架解析-mmlab系列

  • 讲座记录-有意思的文章集合

  • 体会感悟-产品沉思录观后有感

  • 体会感悟-摄影

  • 系列笔记-

  • 系列笔记-乐理和五线谱

  • 系列笔记-爬虫实践

  • 系列笔记-Django学习笔记

  • 系列笔记-Git 使用笔记

  • 系列笔记-网站搭建

  • 系列笔记-图卷积网络

  • 课程笔记-MIT-NULL

  • 系列笔记-OpenCV-Python

  • 系列笔记-使用 Beancount 记账

  • 系列笔记-Python设计模式

  • 系列笔记-MLOps

  • 系列笔记-Apollo自动驾驶

  • 系列笔记-PaddlePaddle

  • 系列笔记-视频操作

  • Vue+Django前后端分离开发

  • 深度学习及机器学习理论知识学习笔记

  • PyTorch Tricks

  • 学习笔记
  • 代码实践-图像分割
Muyun99
2021-05-07

PASCAL VOC 2012调色板 color map生成源代码分析

def putpalette(mask):
    colormap = [[0, 0, 0], [128, 0, 0], [0, 128, 0], [128, 128, 0], [0, 0, 128],
               [128, 0, 128], [0, 128, 128], [128, 128, 128], [64, 0, 0],
               [192, 0, 0], [64, 128, 0], [192, 128, 0], [64, 0, 128],
               [192, 0, 128], [64, 128, 128], [192, 128, 128], [0, 64, 0],
               [128, 64, 0], [0, 192, 0], [128, 192, 0], [0, 64, 128]]

    r = mask.copy()
    g = mask.copy()
    b = mask.copy()

    for cls in range(21):
        r[mask == cls] = colormap[cls][0]
        g[mask == cls] = colormap[cls][1]
        b[mask == cls] = colormap[cls][2]

    # b[mask == cls] = self.colormap[color_cls][2]

    rgb = np.zeros((mask.shape[0], mask.shape[1], 3))
    rgb[:, :, 0] = b
    rgb[:, :, 1] = g
    rgb[:, :, 2] = r

    return rgb.astype('uint8')

# 传入图像的 name 获取图像和标注的路径
dir_img = os.path.join(args.voc12_root, args.img_dir, name+'.jpg')
dir_gt = os.path.join(args.gt_dir, name+'.png')

# 读入灰度图像
img = mmcv.imread(dir_img)
gt = mmcv.imread(dir_gt, flag='grayscale')

# 为灰色标注上色
colored_mask = putpalette(mask)

# 将彩色标注与原图融合
vis_mask = cv2.addWeighted(img, 0.5, colored_mask, 0.5, gamma=0.1)
vis = concat_two_img(img, vis_mask)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39

np 的 阈值化和 torch 的阈值化

threshold, upper, lower = 0.5, 1, 0

a = np.random.rand(4, 4)
a_np = np.where(a > threshold, upper, lower)

a_tensor = torch.from_numpy(a)
a_tensor_torch = torch.where(a_tensor > threshold, upper, lower)
1
2
3
4
5
6
7

参考资料

  • https://yimiandai.me/post/voc-pillow/
上次更新: 2023/03/25, 19:58:09
半监督与弱监督图像分割
语义分割数据集灰度分割图转彩色分割图代码

← 半监督与弱监督图像分割 语义分割数据集灰度分割图转彩色分割图代码→

最近更新
01
Structured Knowledge Distillation for Semantic Segmentation
06-03
02
README 美化
05-20
03
常见 Tricks 代码片段
05-12
更多文章>
Theme by Vdoing | Copyright © 2021-2023 Muyun99 | MIT License
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式
×