用matlab,想在一幅图片上,通过鼠标点击某个点,直接反馈这个点的坐标值,谢谢各位大侠

 我来答
ikanchi
2007-04-29 · TA获得超过2917个赞
知道小有建树答主
回答量:665
采纳率:33%
帮助的人:0
展开全部
function outtrack=mousetrack(inmat)

%MOUSETRACK Track the motion of your mouse over an image
% MOUSETRACK(X) retuns a Mx2 tensor, which containes the x and y position of the
% mouse cursor during it's motion over the selected image 'inmat'. Images can be real RGB image
% data, or any MxN matrix. The recording phase is started and stopped by a
% click on either mousebutton.
%
% Syntax:
%
% outtrack=mousetrack(inmat)
%
% Example:
% d=mousetrack(peaks)
% hold on
% plot(d(:,1),d(:,2),'r')
%
%Author: Ralph Mettier, Paul Scherrer Institute, Villigen Switzerland
%Date: July 21st 2004

try
imagefig=figure('units','normalized','position',[0.1 0.1 0.8 0.8]);
imagesc(inmat)
set(gca,'ydir','normal');
catch
close(imagefig)
disp('Only NxM tensors, or NxMx3 RGB image data can be displayed as images')
end

set(imagefig,'windowbuttondownfcn',{@starttrack});

waitfor(0,'userdata')
outtrack=get(0,'userdata');
% -------------------------------------------------------------------------

function starttrack(imagefig,varargins)

disp('tracking started')
set(gcf,'windowbuttondownfcn',{@stoptrack},'userdata',[]);
set(gcf,'windowbuttonmotionfcn',...
'set(gcf,''userdata'',[get(gcf,''userdata'');get(0,''pointerlocation'')])');

%--------------------------------------------------------------------------

function stoptrack(imagefig,varargins)

set(gcf,'windowbuttonmotionfcn',[]);

disp('tracking stopped')

units0=get(0,'units');
unitsf=get(gcf,'units');
unitsa=get(gca,'units');

set(0,'units','pixels');
set(gcf,'units','pixels');
set(gca,'units','pixels');

x=get(gca,'xlim');
y=get(gca,'ylim');
axsize=get(gca,'position');
figsize=get(gcf,'position');
ratio=diag([diff(x)/axsize(3) diff(y)/axsize(4)]);
shift=figsize(1:2)+axsize(1:2);

set(0,'units',units0);
set(gcf,'units',unitsf);
set(gca,'units',unitsa);

mousetrail=(get(gcf,'userdata')-repmat(shift,size(get(gcf,'userdata'),1),1))*ratio;

set(gcf,'windowbuttondownfcn',{@starttrack});
set(0,'userdata',mousetrail);
% end of code

参考资料: http://bbs.matwav.com/post/view?bid=12&id=658868&sty=1&tpg=3&age=0

推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式