美文网首页
matlab使用鼠标标注图像上的位置

matlab使用鼠标标注图像上的位置

作者: 乘瓠散人 | 来源:发表于2019-02-28 11:44 被阅读12次

使用matlab自带的ginput函数可以返回鼠标在图像上点击的位置坐标,但是无法直接将点在图像上实时显示出来,为此需要修改一下ginput函数。

  • 在matlab中输入edit ginput
  • 大约在第115行附近出现 pt = get(axes_handle, 'CurrentPoint');
    在下面加上这句代码 plot(pt(1,1), pt(1,2), 'r+'); 即可以在图像上用红色+显示鼠标点击的位置
  • 具体的位置坐标位于[x, y] = ginputx, y

以下为遍历文件夹中的所有图像进行标注的代码:

function Save_Samples(folder)
folderpath = fullfile('E:', 'myData', folder);
filepaths = dir(fullfile(folderpath, '*.jpg')); %列出该文件夹下所有.jpg格式的文件

for i = 1:length(filepaths)
    img = imread(fullfile(folderpath, filepaths(i).name)); %读入第i个图片
    %figure;
    imshow(img);
    hold on;
    [x,y] = ginput;
    savePath = [filepaths(i).name, '.mat'];
    save(savePath, 'x', 'y');
    hold off;
end

end

相关文章

网友评论

      本文标题:matlab使用鼠标标注图像上的位置

      本文链接:https://www.haomeiwen.com/subject/gakhuqtx.html