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 = './data/train/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')
# opacity 越小,掩膜效果越深
main(imagePath=img_path, labelPath=mask_path, bgr=(255, 0, 0), opacity=0.5)
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
项目包含:二值分割遥感公路图像分割数据集(划分了训练集和测试集) 数据集为卫星影像下的道路分割数据集,前景目标丰富且标注效果极好,可以用于分割网络实战 数据集总大小:237MB 数据集介绍:分为训练集、测试集 训练集:images图片目录+masks模板目录,1340张图片和1340个对应的mask图片 测试集:images图片目录+masks模板目录,334张图片和334个对应的mask图片 除此之外,包含一个图像分割的可视化脚本,随机提取一张图片,将其原始图片、GT图像、GT在原图蒙板的图像展示,并保存在当前目录下
资源推荐
资源详情
资源评论
收起资源包目录
深度学习之图像分割数据集:二值分割遥感公路图像分割数据集(划分了训练集和测试集) (2000个子文件)
W1376.png 161KB
W714.png 159KB
W1325.png 159KB
W1307.png 158KB
W960.png 158KB
W928.png 157KB
W949.png 157KB
W102.png 157KB
W719.png 157KB
W1020.png 156KB
W984.png 156KB
W50.png 156KB
W546.png 156KB
W550.png 156KB
W964.png 156KB
W942.png 155KB
W932.png 155KB
W915.png 155KB
W552.png 155KB
W832.png 155KB
W926.png 154KB
W867.png 154KB
W1526.png 154KB
W857.png 154KB
W826.png 154KB
W681.png 154KB
W1067.png 154KB
W562.png 154KB
W517.png 153KB
W946.png 153KB
W362.png 153KB
W799.png 153KB
W843.png 153KB
W966.png 153KB
W1109.png 153KB
W800.png 153KB
W695.png 153KB
W1436.png 153KB
W1438.png 153KB
W834.png 153KB
W715.png 153KB
W729.png 153KB
W579.png 153KB
W1012.png 153KB
W540.png 153KB
W734.png 153KB
W1066.png 153KB
W524.png 153KB
W511.png 153KB
W830.png 153KB
W814.png 153KB
W772.png 153KB
W897.png 152KB
W608.png 152KB
W827.png 152KB
W1043.png 152KB
W505.png 152KB
W690.png 152KB
W1050.png 152KB
W922.png 152KB
W530.png 152KB
W525.png 152KB
W679.png 152KB
W754.png 152KB
W48.png 152KB
W589.png 152KB
W686.png 152KB
W571.png 152KB
W367.png 152KB
W514.png 152KB
W368.png 152KB
W844.png 152KB
W488.png 152KB
W1033.png 152KB
W806.png 152KB
W817.png 152KB
W619.png 152KB
W358.png 152KB
W892.png 152KB
W1089.png 152KB
W81.png 151KB
W684.png 151KB
W896.png 151KB
W672.png 151KB
W708.png 151KB
W493.png 151KB
W710.png 151KB
W103.png 151KB
W490.png 151KB
W599.png 151KB
W813.png 151KB
W1388.png 151KB
W745.png 151KB
W641.png 151KB
W1030.png 151KB
W581.png 151KB
W607.png 151KB
W874.png 151KB
W689.png 151KB
W856.png 151KB
共 2000 条
- 1
- 2
- 3
- 4
- 5
- 6
- 20
资源评论
听风吹等浪起
- 粉丝: 1w+
- 资源: 1331
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功