图像分割 json文件 批量转mask

这篇博客介绍了如何使用Labelme工具的json_to_dataset.py脚本将大量JSON标注文件转换为图像分割所需的Mask格式。首先从GitHub下载Labelme,然后修改脚本以适应批量转换,并指定输入和输出目录。转换过程包括读取JSON文件,解码图像数据,创建Label,并保存为PNG图像和对应的Mask。最终,转换后的Mask是8位,原图是24位,适合作为训练模型的输入。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

图像分割 json文件 批量转mask

在进行labelme进行标注后有大量json文件,如果做图像分割需要转为mask才能进入进行训练

1.下载labelme
去github上搜索labelme,用git clone 下载

2.修改json_to_dataset.py 文件路径:label/label/cil/json_to_dataset.py

import argparse
import base64
import json
import os
import os.path as osp

import imgviz
import PIL.Image

from labelme.logger import logger
from labelme import utils


def main(file, outfile):
    logger.warning(
        "This script is aimed to demonstrate how to convert the "
        "JSON file to a single image dataset."
    )
    logger.warning(
        "It won't handle multiple JSON files to generate a "
        "real-use dataset."
    )

    parser = argparse.ArgumentParser()
    parser.add_argument("--json_file", default=file)
    parser.add_argument("-o", "--out", default=outfile)
    args = parser.parse_args()

    json_file = args.json_file

    if args.out is None:
        out_dir = osp.basename(json_file).replace(".", "_")
        out_dir = osp.join(osp.dirname(json_file), out_dir
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值