我使用MATLAB中的ginput函数来使用光标收集图像上的多个x,y坐标。我沿着图像遵循一定的路径,需要放大以获得精确的坐标,但是在使用ginput时禁用了缩放选项。对如何绕过这个问题有什么想法吗?
下面是我使用的非常简单的代码。
A = imread('image1.tif');
B = imshow(A);
[x,y] = ginput;
% at this point i scan the image and click many times, and
% ideally i would like to be able to zoom in and out of the image to better
% aim the cursor and obtain precise xy coordinates发布于 2015-09-17 01:05:21
我认为这样做的方法是利用ginput函数的“按钮”输出,即,
[x,y,b]=ginput;
b返回按下的鼠标按钮或键盘键。选择您最喜欢的两个键(例如和字符91和93号),并编写一些缩放/缩放代码,以处理按下这些键时发生的情况:
A = imread('image1.png');
B = imshow(A);
X = []; Y = [];
while 0<1
[x,y,b] = ginput(1);
if isempty(b);
break;
elseif b==91;
ax = axis; width=ax(2)-ax(1); height=ax(4)-ax(3);
axis([x-width/2 x+width/2 y-height/2 y+height/2]);
zoom(1/2);
elseif b==93;
ax = axis; width=ax(2)-ax(1); height=ax(4)-ax(3);
axis([x-width/2 x+width/2 y-height/2 y+height/2]);
zoom(2);
else
X=[X;x];
Y=[Y;y];
end;
end
[X Y](1)在ginput(1)中非常重要,因此每次只需单击一次/键即可。
enter键是默认的ginput中断键,它返回一个空的b,由第一个if语句处理。
如果按下91或93键,我们将分别放大(zoom(1/2))或放大(zoom(2))。使用axis的两条线以光标上的图形为中心,并且很重要,这样您就可以放大图像的特定部分。
否则,将光标坐标x,y添加到您的坐标集X,Y中。
发布于 2021-01-11 14:16:10
还有一种方法可以是使用函数enableDefaultInteractivity(),它允许使用鼠标轮放大和缩小:
enableDefaultInteractivity(gca);
[x, y, b] = ginput();我的Matlab版本(9.9.0.1524771 (R2020b)更新2,在Linux上)运行得很好。
https://stackoverflow.com/questions/32620675
复制相似问题