用matlab做一个高效的辅助标注工具

最近准备做人工智能–深度学习方面的研究,主要方向是计算机视觉,先行的准备工作就是做数据集,包括训练集和测试集。由于算法的目标是大数据的,单训练集就要人工标注5W+的图片,所以用matlab做了一个辅助的工具来快速标注。(初学matlab,不足之处,请指正)

准备工作

先确定工具的基本功能:
1. 在图片上用矩形框圈出若干区域,每个区域打上一个标签;
2. 把图片的标注信息输出到一个txt文件中,标注信息包括:区域left,top坐标,宽度,高度,标签,每个标注一行;

额外的功能:

额外的功能是为了提高标注效率而加入的功能

  1. 要标注大量的图片,自然要在标注完一张后自动加载下一张;
  2. 批量标注:在现实生活中,往往存在大量同属性的物体的聚合,如公路中车的方向就径谓分明地分成两个方向,所以应有全选+标注,即一键标注全部选定框的功能;
  3. 在功能2的基础上,应有多选标注功能,便于对混合的场合进行修改;
  4. 为便于多人合作,应能自动载入已标记信息

工具主体

主函数

function aidedLabel3()
clear;
clc;
imageDir = 'E:\test\';
outputDir = 'E:\test\';
if ~exist(imageDir, 'file') % 看图像目录是否存在,不存在则指出
    msgbox('Invalid Directory!');
end

if ~exist(outputDir, 'file') % 看输出目录是否存在,不存在则创建
    mkdir(outputDir);
end

pictureList = dir(strcat(imageDir, '\*.jpg')); % 先读入所有图片的name及数量
pictureSum = length(pictureList);

imHandle = figure('menubar','none');

% 设置一些gui间传递的参数信息,包括当前显示的图片标号,图片名称列表,
% 所在文件夹地址,图片总量,输出文件夹地址等
% mode用于后面的多选标注
count = 1;
mode = 0;
set(imHandle, 'Tag', 'Frame');
setappdata(imHandle, 'imageIndex', count);
setappdata(imHandle, 'pictureList', pictureList);
setappdata(imHandle, 'imageDir', imageDir);
setappdata(imHandle, 'pictureSum', pictureSum);
setappdata(imHandle, 'outputDir', outputDir);
setappdata(imHandle, 'mode', mode);

% 设置鼠标点击回调函数,图片窗口关闭函数,按键反馈调度函数
set(gcf, 'WindowButtonDownFcn', @MouseClickFcn);
set(gcf, 'Closerequestfcn', @Closerequestfcn);
set(gcf, 'Keypressfcn', @Keypressfcn);

% 都设置好了后,载入图片
loadImage();
end

功能函数

function loadImage()
handleFrame = findobj('Tag', 'Frame'); % 通过Tag找到主界面的handle
imageIndex = getappdata(handleFrame, 'imageIndex'); 
pictureList = getappdata(handleFrame, 'pictureList');
imageDir = getappdata(handleFrame, 'imageDir');
pictureSum = getappdata(handleFrame, 'pictureSum');

% 如果图片编号在范围内,就把图片加载进来
if imageIndex <= pictureSum
    pictureDir = strcat(imageDir, pictureList(imageIndex).name);
    outDir = getappdata(handleFrame, 'outputDir');
    outFile = [outDir pictureList(imageIndex).name '.txt'];
    setappdata(handleFrame, 'outFile', outFile);
    im = imread(pictureDir);
    imshow(im);

    % 设置菜单选项,主要实现辅助功能
    menuLabelAll = uimenu(gcf, 'label', 'LabelAll');
    menuLabelAll2a = uimenu(menuLabelAll, 'label', 'a', 'callback', 'labelAll2a');
    menuLabelAll2b = uimenu(menuLabelAll, 'label', 'b', 'callback', 'labelAll2b');
    menuLabelAll2c = uimenu(menuLabelAll, 'label', 'c', 
  • 10
    点赞
  • 24
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值