引言
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

该博客介绍了在Matlab中如何实现图像处理时获取用户鼠标点击的坐标值。通过创建figure,启用数据光标模式,并设置更新函数,当用户在图像上点击时,可以捕获并显示点击位置的坐标值。
最低0.47元/天 解锁文章
1212

被折叠的 条评论
为什么被折叠?



