其他分享
首页 > 其他分享> > 语义分割 结果叠加原图像方法

语义分割 结果叠加原图像方法

作者:互联网

#1
是alpha,beta两个参数
img1 = cv.imread(“1.jpg”)
img2 = cv.imread(“2.jpg”)
img_add = cv.addWeighted(img1, alpha, img2, beta, gamma)

#2 这个方法是复制的,原文链接如下:
添加链接描述

# 将分割图和原图合在一起
from PIL import Image
import matplotlib.pyplot as plt
 
#image1 原图 
#image2 分割图
image1 = Image.open("1.jpg")
image2 = Image.open("1.png")
 
plt.figure()
 
plt.subplot(221)
plt.imshow(image1)
 
plt.subplot(222)
plt.imshow(image2)
 
plt.subplot(223)
plt.imshow(image1)
plt.imshow(image2,alpha=0.5)
 
plt.show()

在这里插入图片描述

# 将分割图和原图合在一起
from PIL import Image
import matplotlib.pyplot as plt
 
#image1 原图 
#image2 分割图
image1 = Image.open("1.jpg")
image2 = Image.open("1.png")
 
image1 = image1.convert('RGBA')
image2 = image2.convert('RGBA')
 
#两幅图像进行合并时,按公式:blended_img = img1 * (1 – alpha) + img2* alpha 进行
image = Image.blend(image1,image2,0.3)
image.save("test.png")
image.show()

在这里插入图片描述
#3 原文链接如下
添加链接描述

imgfile = 'image.jpg'
pngfile = 'mask.png'

img = cv2.imread(imgfile, 1)
mask = cv2.imread(pngfile, 0)

contours, _ = cv2.findContours(mask, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
cv2.drawContours(img, contours, -1, (0, 0, 255), 1)

img = img[:, :, ::-1]
img[..., 2] = np.where(mask == 1, 255, img[..., 2])

plt.imshow(img)
plt.show()
weixin_43436587 发布了2 篇原创文章 · 获赞 0 · 访问量 22 私信 关注

标签:叠加,plt,img,cv2,Image,语义,图像,image2,image1
来源: https://blog.csdn.net/weixin_43436587/article/details/104538635