对于图像分割的任务,往往将原图与目标分割图像叠加显示会得到一张很好的mask示意图,本篇博客就跟大家分享一下如何在python中叠加显示多张图片
叠加显示下面两张图片,他们的像素都是,区别是左边的是三通道彩色图像,右边的是单通道灰度图像
依赖的库与环境
import torch
from PIL import Image
import numpy as np
import matplotlib.pyplot as plt
# 获取图片路径
img_path = r"D:\py-code\bio_seg\Vessel-wgan-pytorch\eyedata\train\img\21_training.tif"
label_path = r"D:\py-code\bio_seg\Vessel-wgan-pytorch\eyedata\train\label\21_training.gif"
# 读取图片数据
img = Image.open(img_path)
label = Image.open(label_path)
# 将数据转换成tensor类型并且对其像素格式
img = torch.tensor(np.array(img))
label = torch.tensor(np.array(label))
label = label.unsqueeze(2)
print(img.shape)
print(label.shape)
# 在第2个维度上合并两张图片并显示
merge = torch.cat((img,label),dim=2)
plt.imshow(merge)
plt.show()
效果显示