【图像语义分割】Labelme(python)安装

在进行监督学习,需要对目标进行标记,从而生成自己的模型。这里用到了一款标记软件:Labelme

下载地址:

https://github.com/wkentaro/labelme

安装:

conda create --name=labelme python=3.6
source activate labelme
conda install pyqt
pip3 install labelme

 安装成功后,终端输入:labelme

1.点击open打开需要标记的图片。

2.点击Create polygons

3.保存

 保存后可得到一个json文件。

我们需要转换成我们可以处理的数据。json对我们来说还是要转换为单通道的image

终端输入:

labelme_json_to_dataset <文件名>.json

即可得到一个文件夹,有四个文件,*.png, info.yaml , label.png, label_viz.png。
其中label.png即是我们要的label_data. 

即标注完成

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是一个示例的Python代码,用于对指定类别的labelme标注的语义分割数据进行增强: ```python import os import cv2 import numpy as np def semantic_segmentation_augmentation(directory, save_directory, target_class): # 遍历指定目录下的文件 for filename in os.listdir(directory): if filename.endswith(".json"): # 查找以.json结尾的文件 json_file = os.path.join(directory, filename) image_file = json_file.replace(".json", ".jpg") # 将.json替换为.jpg if os.path.isfile(image_file): # 检查对应的图片文件是否存在 # 读取图片文件 image = cv2.imread(image_file) height, width, _ = image.shape # 读取JSON文件并获取标注信息 with open(json_file, 'r') as f: json_data = json.load(f) # 创建空白的语义分割图像 seg_image = np.zeros((height, width), dtype=np.uint8) # 处理每个标注对象 for shape in json_data['shapes']: class_name = shape['label'] if class_name == target_class: points = shape['points'] polygon_points = np.array(points, dtype=np.int32) cv2.fillPoly(seg_image, [polygon_points], 255) # 将增强后的语义分割图像保存到指定目录 save_path = os.path.join(save_directory, filename.replace(".json", ".png")) cv2.imwrite(save_path, seg_image) print(f"语义分割图像保存成功:{save_path}") else: print(f"找不到对应的图片文件:{image_file}") # 指定包含labelme标注文件的目录和保存增强后数据的目录 directory = "path/to/labelme/files" save_directory = "path/to/save/augmented/data" # 指定目标类别名称 target_class = "class_name" semantic_segmentation_augmentation(directory, save_directory, target_class) ``` 你需要将代码中的`"path/to/labelme/files"`替换为包含标注文件的实际目录路径,将`"path/to/save/augmented/data"`替换为你想要保存增强后数据的目录路径,将`"class_name"`替换为你想要增强的目标类别名称。运行代码后,它会遍历目录中的所有.json文件,读取标注信息并创建相应的语义分割图像,然后将增强后的语义分割图像保存到指定目录。 希望这可以帮到你!如果有任何问题,请随时问我。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值