r9 *_*fan 3 matlab image-processing zooming coordinates ginput
我正在使用ginput
MATLAB中的函数来使用光标来收集图像上的许多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
Run Code Online (Sandbox Code Playgroud)
我认为这样做的方法是利用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]
Run Code Online (Sandbox Code Playgroud)
该(1)
中ginput(1)
很重要,这样你只获得点击/按键在同一时间.
enter键是默认的ginput
break键,它返回一个空值b
,由第一个if
语句处理.
如果按下键91或93,我们分别缩小(zoom(1/2)
)或放大(zoom(2)
).这对情侣线使用axis
光标中心绘图,并且非常重要,因此您可以放大图像的特定部分.
否则,将光标坐标添加x,y
到您的坐标集X,Y
.