210812-Matlab获得图像中鼠标点击坐标

引言

Matlab图像处理中,有时需要获得鼠标在图像中点击的坐标值,以下是调用代码。
代码如下:

function [x,y]=get_cursor_value(image,title_name)
%     img=dicomread(image);
    fig=figure;
    imshow(image,[])
    title(title_name);
    title(title_name,'Interpreter','none')
    set(gcf,'position',[0,0,1300,1300])
    % Enable data cursor mode
    datacursormode on
    dcm_obj = datacursormode(fig);
    % Set update function
    set(dcm_obj,'UpdateFcn',@myupdatefcn)
    % Wait while the user to click
    disp('Click line to display a data tip, then press "Return"')
    pause 
    % Export cursor to workspace
    info_struct = getCursorInfo(dcm_obj);
    if isfield(info_struct, 'Position')
      disp('Clicked positioin is')
      disp(info_struct.Position)
      x=info_struct.Position(1);
      y=info_struct.Position(2);
    end
    close all
    function output_txt = myupdatefcn(~,event_obj)
      % ~            Currently not used (empty)
      % event_obj    Object containing event data structure
      % output_txt   Data cursor text
      pos = get(event_obj, 'Position');
      output_txt = {['x: ' num2str(pos(1))], ['y: ' num2str(pos(2))]};
    end
end
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值