matlab鼠标截取图像并显示_在matlab指南中用鼠标悬停在图像上时如何显示不同的信息?...

在MATLAB中,可以通过创建一个图形界面,并设置鼠标移动回调函数来实现在图像上显示弹出式信息。当鼠标在图像上移动时,回调函数会更新一个UI面板的位置,显示当前位置的像素值。此功能适用于图像分析和交互式应用。
摘要由CSDN通过智能技术生成

我不是100%明白“几个标签”的含义,但我认为你希望能够在图像上显示弹出式编辑,我认为以下是你想要的:

function hoverTest

% create a figure (units normalized makes updating the position easier in the callback

f = figure ( 'units', 'normalized' );

% create an axes

ax = axes ( 'parent', f );

% load some data for plotting

c = load ( 'clown' );

% plot the data

image ( c.X, 'parent', ax );

% create a uipanel to host the text we will display

uip = uipanel ( 'parent', f, 'position', [0 0 0.18 0.05], 'visible', 'off' );

% create a text control to display the image info

txt = uicontrol ( 'style', 'edit', 'parent', uip, 'units', 'normalized', 'position', [0 0 1 1] );

% assign the callback for when the mouse moves

f.WindowButtonMotionFcn = @(obj,event)updateInfo(f,uip,ax,txt,c.X);

end

function updateInfo ( f, uip, ax, txt,img )

% update the position of the uipanel - based on the current figure point (normalized units)

set ( uip, 'Position', [f.CurrentPoint uip.Position(3:4)] );

% Check to see if the figure is over the axes (if not hide)

if ax.CurrentPoint(1,1) < min(ax.XLim) || ...

ax.CurrentPoint(1,1) > max(ax.XLim) || ...

ax.CurrentPoint(1,2) < min(ax.YLim) || ...

ax.CurrentPoint(1,2) > max(ax.YLim)

uip.Visible = 'off';

else

% show the panel

uip.Visible = 'on';

% get the current point

cp = round(ax.CurrentPoint);

% update the text string of the uicontrol

txt.String = sprintf ( 'img(%i,%i) = %i', cp(1,1), cp(1,2), img(cp(1,2),cp(1,1) ) );

end

end

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值