图像分割将标注(label)的mask表示在图像image上

分割中将label和原图image表示在一起

import matplotlib.pyplot as plt

image = plt.imread('./image.png')
mask = plt.imread('./mask.png')
pred = plt.imread('./pred.png')

fig, ax = plt.subplots()
ax.imshow(image)
ax.imshow(mask, cmap='gray', alpha=0.5)
# 预测结果也表示出来
ax.imshow(pred, cmap='gray', alpha=0.5)

# fig.show()
fig.savefig('./overlapped.png')

原文链接:link

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
LabelImg格式转换为COCO数据格式的方法如下: 1. 首先,在电脑上安装Python的cocoapi库: ``` pip install pycocotools ``` 2. 然后,创建一个Python脚本,导入必要的库: ```python import json import os from PIL import Image from pycocotools import mask ``` 3. 接着,读取LabelImg生成的XML文件和图像文件,将它们转换为COCO格式的json文件: ```python # 设置路径和文件名 image_folder = '/path/to/image/folder' label_folder = '/path/to/xml/annotations/folder' output_file = 'output_coco.json' # 创建COCO格式的json对象 coco = { 'images': [], 'categories': [], 'annotations': [] } # 添加类别信息 category = {'id': 1, 'name': 'your_class_name', 'supercategory': 'object'} coco['categories'].append(category) # 读取并处理每个图像标注信息 image_id = 0 annotation_id = 0 for label_file in os.listdir(label_folder): if label_file.endswith('.xml'): image_id += 1 image_file = label_file.replace('.xml', '.jpg') image_path = os.path.join(image_folder, image_file) # 添加图像信息 img = Image.open(image_path) image_info = {'file_name': image_file, 'height': img.height, 'width': img.width, 'id': image_id} coco['images'].append(image_info) # 解析XML文件 with open(os.path.join(label_folder, label_file), 'r') as f: # 在此根据需要解析XML文件并生成对应的COCO标注信息 # 每个标注信息需包含'bbox': [x, y, width, height], 'area': area, 'image_id': image_id, 'category_id': 1, 'id': annotation_id # 其中x, y, width, height为标注框的左上角坐标和宽高,area为标注框的面积 # 注意:COCO数据集中的坐标原点在左上角,像素从0开始计数 # 添加标注信息到coco coco['annotations'].append(annotation_info) # 增加当前图像标注id annotation_id += 1 # 将coco对象保存为json文件 with open(output_file, 'w') as f: json.dump(coco, f) ``` 请根据需要修改`image_folder`,`label_folder`和`output_file`的路径。上述代码将标注类别设为'your_class_name',可以根据实际情况进行修改。 以上就是将LabelImg格式转换为COCO数据格式的简单方法。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值