灰度保存为彩色图片

 target为灰度,prediction为RGB

  在实例分割中,有时需要我们的训练数据是灰度图.但是我们的最终预测结果是彩色图(RGB),所以,在比较最后的分割效果的时候,可能需要我们同时生成prediction和target进行比对.

one:

from PIL import Image

label=igg   # nparray
bin_colormap = np.random.randint(0, 255, (256, 3))

bin_colormap = np.random.randint(0, 255, (256, 3))      # 可视化的颜色
bin_colormap = bin_colormap.astype(np.uint8)
visualimg  = Image.fromarray(label, "P")
palette = bin_colormap          #long palette of 768 items
visualimg.putpalette(palette) 
visualimg.save("F:/im", format='PNG')

two:

plt.imshow(igg)
plt.savefig('F:/test2.jpg')

 

 保存的图片:

 

posted @ 2021-05-25 16:47  为红颜  阅读(225)  评论(0编辑  收藏  举报