grabbing the index value from the pointer when clicking on the image in MATLAB

若如初见. 提交于 2019-12-24 01:55:28

问题


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

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


回答1:


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);


来源:https://stackoverflow.com/questions/42353878/grabbing-the-index-value-from-the-pointer-when-clicking-on-the-image-in-matlab

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!