在MATLAB中单击图像时从指针获取索引值 [英] grabbing the index value from the pointer when clicking on the image in MATLAB

查看:261
本文介绍了在MATLAB中单击图像时从指针获取索引值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在单击时找到一个点的索引,并将其添加到数组,列表或向量的末尾?

How can I find the index of a point on click on and add it to end of an array, list or vector?

h=figure;
image(result);
locx = [];
locy = [];
while (ishandle(h))
    pos = get(0, 'PointerLocation');
    locx(end + 1) = pos(1);
    locy(end + 1) = pos(2);
    pause(1);
end

虽然我只单击了两个点以查看它们的x,y和索引,但是许多x位置已保存在locx数组中.请提出解决方案和修正:

While I have only clicked on two points to see their x,y and index, many x locations has been saved in locx array. Please suggest solution and fixes:

locx =

  Columns 1 through 16

         635        1116         231         758         771         591         596          46         116         116         116        1362         852         498        1920        1663

  Columns 17 through 32

         733         795         795        1920        1895        1806        1061         700         123        1102        1097        1615           1         226         233         233

  Columns 33 through 43

         191         854         836        1920        1920        1920        1920        1920        1905        1189        1912

推荐答案

我建议使用

I would suggest using the ginput function instead:

h = figure;
image(result);
[locx, locy] = ginput(2);

这将为您提供轴内的点,必须通过四舍五入将其转换为图像的索引:

This will give you points within the axes, which will have to be converted to indices into the image by rounding them off:

locx = round(locx);
locy = round(locy);

这篇关于在MATLAB中单击图像时从指针获取索引值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆