在 MATLAB 中单击图像时从指针中获取索引值
grabbing the index value from the pointer when clicking on the image in MATLAB
如何找到点击的点的索引并将其添加到数组、列表或向量的末尾?
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数组中。请提出解决方案和修复:
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
我建议改用 ginput
函数:
h = figure;
image(result);
[locx, locy] = ginput(2);
这将为您提供轴内的点,必须通过四舍五入将其转换为图像中的索引:
locx = round(locx);
locy = round(locy);
如何找到点击的点的索引并将其添加到数组、列表或向量的末尾?
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数组中。请提出解决方案和修复:
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
我建议改用 ginput
函数:
h = figure;
image(result);
[locx, locy] = ginput(2);
这将为您提供轴内的点,必须通过四舍五入将其转换为图像中的索引:
locx = round(locx);
locy = round(locy);