深度学习|将多类分割灰度标签图转RGB三通道图

*************************************************** 码字不易,收藏之余,别忘了给我点个赞吧! *************************************************** ---------Start 灰度标签图:
0,1,2,3,4分别代表:background,car,wheel,lights,window五个类别。显示全黑。
深度学习|将多类分割灰度标签图转RGB三通道图
文章图片

代码:
prediction代表读入的标签numpy数组(灰度图读入)

prediction = cv.imread('test.png',flag=0) a1 = copy.deepcopy(prediction) a2 = copy.deepcopy(prediction) a3 = copy.deepcopy(prediction)a1[a1 == 1] = 255 a1[a1 == 2] = 0 a1[a1 == 3] = 255 a1[a1 == 4] = 20a2[a2 == 1] = 255 a2[a2 == 2] = 255 a2[a2 == 3] = 0 a2[a2 == 4] = 10a3[a3 == 1] = 255 a3[a3 == 2] = 77 a3[a3 == 3] = 0 a3[a3 == 4] = 120a1 = Image.fromarray(np.uint8(a1)).convert('L') a2 = Image.fromarray(np.uint8(a2)).convert('L') a3 = Image.fromarray(np.uint8(a3)).convert('L') prediction = Image.merge('RGB', [a1, a2, a3]) prediction.save('test2.png')

转换的RGB图片:
【深度学习|将多类分割灰度标签图转RGB三通道图】通过手动设置三通道的RGB值,实现(0,1,2,3,4)到五种RGB颜色的转换。
深度学习|将多类分割灰度标签图转RGB三通道图
文章图片

至此,设置完毕!

    推荐阅读