import cv2
import numpy as np
import os
import random
from PIL import Image
import matplotlib.pyplot as plt
# https://blog.csdn.net/qq_44886601/article/details/135764589
# 将mask绘制在原图
def draw_image(im, ms, brg, opacity):
image_mask = im.copy()
contours, _ = cv2.findContours(ms, cv2.RETR_TREE, cv2.CHAIN_APPROX_NONE) # 查找轮廓
image_mask = cv2.drawContours(image_mask, contours, -1, (0, 255, 0), 2) # 绘制边界
image_mask = cv2.fillPoly(image_mask, contours, color=brg) # 填充
img_bgr = cv2.addWeighted(im, opacity, image_mask, 1 - opacity, 0)
return im, ms, img_bgr
def main(imagePath, labelPath, bgr, opacity):
image = np.array(Image.open(imagePath).convert('RGB'))
label = np.array(Image.open(labelPath).convert('L'))
a, b, c = draw_image(image, label, bgr, opacity)
plt.figure(figsize=(12, 8))
for index, i in enumerate((a, b, c)):
plt.subplot(1, 3, index + 1)
plt.imshow(i)
plt.savefig('./result.png')
# plt.show()
if __name__ == '__main__':
root = './images'
images_path = [os.path.join(root, i) for i in os.listdir(root)]
r = random.randint(0, len(images_path) - 1)
img_path = images_path[r] # 随机取出一张图片
mask_path = img_path.replace('images', 'masks')
mask_path = mask_path.replace('.JPG', '.png')
# opacity 越小,掩膜效果越深
main(imagePath=img_path, labelPath=mask_path, bgr=(0, 0, 255), opacity=0.5)
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
项目包含高压线图像分割数据集(二值图像分类),文件以文件夹格式储存,可直接用作图像分割数据集,无需额外处理。 数据集总大小:84MB,总共有40张数据和mask模板 包含一个图像分割的可视化脚本,随机提取一张图片,将其原始图片、GT图像、GT在原图蒙板的图像展示,并保存在当前目录下
资源推荐
资源详情
资源评论
收起资源包目录
dataset.zip (82个子文件)
a
show.py 1KB
masks
039.png 197KB
009.png 505KB
011.png 821KB
025.png 109KB
035.png 101KB
006.png 276KB
003.png 343KB
033.png 103KB
001.png 515KB
034.png 170KB
032.png 198KB
010.png 527KB
008.png 511KB
021.png 705KB
028.png 231KB
004.png 328KB
020.png 719KB
038.png 268KB
036.png 259KB
005.png 184KB
007.png 398KB
019.png 639KB
027.png 53KB
022.png 154KB
016.png 443KB
013.png 597KB
024.png 84KB
017.png 421KB
031.png 185KB
018.png 421KB
015.png 766KB
030.png 172KB
029.png 181KB
023.png 80KB
012.png 550KB
002.png 109KB
026.png 197KB
040.png 369KB
014.png 968KB
037.png 279KB
result.png 173KB
images
009.JPG 2.08MB
012.JPG 2.64MB
030.JPG 845KB
004.JPG 1.09MB
001.JPG 3.95MB
003.JPG 2.03MB
013.JPG 3.17MB
017.JPG 1.13MB
040.JPG 1.42MB
029.JPG 685KB
031.JPG 1.59MB
007.JPG 1.69MB
016.JPG 1.15MB
039.jpg 845KB
033.JPG 2.22MB
028.JPG 1.16MB
022.JPG 1.79MB
019.JPG 1.79MB
023.JPG 373KB
008.JPG 3.34MB
032.JPG 1.41MB
025.JPG 778KB
011.JPG 3.26MB
020.JPG 3.3MB
010.JPG 3.36MB
024.JPG 413KB
034.JPG 1.52MB
021.JPG 3.8MB
027.JPG 711KB
026.JPG 1.78MB
015.JPG 3.93MB
036.JPG 835KB
006.JPG 1.46MB
038.JPG 565KB
002.JPG 482KB
037.JPG 733KB
005.JPG 1.29MB
014.JPG 3.3MB
018.JPG 2.17MB
035.JPG 565KB
共 82 条
- 1
资源评论
听风吹等浪起
- 粉丝: 1w+
- 资源: 1439
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功