Matlab 图像像素级标注

本文介绍了使用 Matlab 2020a 进行图像像素级标注的方法。先在命令行输入 imageLabeler 启动 Image Labeler,选择图像并设置 ROI Labels 进行标注,标注结束后保存文件。还说明了保存文件的相关情况,可将标注保存为 csv 文件,最后能查看标注后的图像效果。

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

目录

一、Matlab 版本:2020a

二、启动 Image Labeler

三、图像像素级标注

1、Load 选择一张图像 设置ROI Labels 

2、标注结束,保存文件 Export Lables -->to files,

3、保存文件说明

4、标注保存为csv文件

5、查看标注后的图像

6、最终的效果


一、Matlab 版本:2020a

 

二、启动 Image Labeler

matlab 命令行输入 imageLabeler,回车,打开界面

三、图像像素级标注

1、Load 选择一张图像 设置ROI Labels 

2、标注结束,保存文件 Export Lables -->to files,

3、保存文件说明

保存路径下有两个文件,在文件夹中打开Label_1.png 会是一张黑色的图像,要在matlab 中打开。

4、标注保存为csv文件

双击Label.png 图像,弹出对话框点击完成

在工作去会显示Lable_1 和图像的尺寸,标注(背景为0 ,分类标注1,2,.....)

双击打开,再ctrl+A全选,复制到 excel文件中,另存为csv就可以了。

5、查看标注后的图像

def csv2Img(csvFile,colorKey=None,filePath=None):
    '''
    将标记的csv转换成图像
    --------
    :param csvFile: 标注的文件路径
    :param colorKey: 类对应的RGB值
    :param filePath: 图片保存路径
    :return: None

    '''
    if colorKey==None:
        colorKey = {1: [0, 0, 255], 2: [0, 255, 0], 3: [255, 0, 0], 4: [128, 128, 128]}  
    # Colour key
    ground_truth = np.loadtxt(open(csvFile, "rb"), delimiter=',', skiprows=0)
    csv_shape = ground_truth.shape
    imgPlace = np.zeros(shape=(csv_shape[0], csv_shape[1], 3))
    for x in range(0, csv_shape[1]):
        for y in range(0, csv_shape[0]):
            if ground_truth[y][x]==1:
                print()
            color = colorKey.get(ground_truth[y][x])
            imgPlace[y, x, :] = color

    cv2.imshow(filePath, imgPlace)
    cv2.imwrite(filePath, imgPlace)
    cv2.waitKey(0)

    print("csv to img finish 。。。。path:"+filePath)
# 根据自己的类,设置colourkey 值
colourkey = {1: [234, 217, 153], 2: [0, 242, 255], 3:[128, 128, 128]}
csv2Img("imge_lable.csv", colorKey=colourkey,filePath="test.png")

6、最终的效果

原始图像:

像素标注的图像:

 

评论 12
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值