MATLAb-----7--------如何动态显示鼠标的坐标值和图像像素值
2012-04-12 21:17
579 查看
MATLAB如何动态显示鼠标的坐标值和图像像素值
http://apps.hi.baidu.com/share/user/41caedc2bda36d61746c6162330a
(1)fix(x) : 截尾取整.
>> fix( [3.12 -3.12])
ans =
3 -3
(2)floor(x):不超过x 的最大整数.(高斯取整)
>> floor( [3.12 -3.12])
ans =
3 -4
(3)ceil(x) : 大于x 的最小整数
>> ceil( [3.12 -3.12])
ans =
4 -3
(4)四舍五入取整
>> round(3.12 -3.12)
ans =
0
>> round([3.12 -3.12])
ans =
3 -3
对于动态显示鼠标的坐标值和像素值,在其他语言如vc,vb中都比较方便,有直接的着方面的函数,那么在matlab图像处理里面又如何实现呢?
具体的实现方法很多,但归结起来就是获取坐标轴的current point 属性值,我这里给出的一个函数是从mathworks 获取柄稍作修改后的结果,相信对做图像处理的朋友有一定的作用。另一个就是自带的pixval函数。谁有不同的实现方法,请多多共享啊!
function dynpoint(arg,h)
% Show the coordinates of a plot dynamically
%
% To start use:
% dynpoint(h)
% where h is a handle to a figure, axes or e.g. line.
%
% To delete use:
% dynpoint('delete',h)
% where h is a handle to a figure, axes or e.g. line.
% (you may also use: dynpoint delete)
%
% There can only be one dynamic plotter in a figure at a time.
%
% Example:
% subplot(211), hline = plot(sin(1:10))
% subplot(212), plot(sin(1:100))
% dynpoint(hline)
% 2002,6.29
if ~exist('arg','var')
arg = gcf;
end
if ~isstr(arg)
handle = arg;
arg = 'init';
end
switch arg
case 'init'
if ~ishandle(handle)
error('h is not a handle')
end
[h,ax] = h2hax(handle);
% delete old dynamic text object
ht = findobj(h,'tag',[mfilename '_text']);
if any(ht)
delete(ht)
end
% text window at the bottom left corner
% text in centred
uicontrol(h,...
'style','text',...
'pos',[2 2 200 15],...
'tag',[mfilename '_text'],...
'userdata',ax(1))
% do the dynamic thing...
set(h,'windowbuttonmotionfcn',[mfilename ' move'])
case 'move'
ht = findobj(gcbf,'tag',[mfilename '_text']);
ax = overobj('axes');
if ~any(ax)
ax = get(ht,'userdata');
end
p = get(ax,'currentpoint');
set(ht,'string',sprintf('(%g, %g)', p(1), p(3)));
case 'delete'
if ~exist('h','var')
h = gcf;
end
[h,ax] = h2hax(h);
set(h,'windowbuttonmotionfcn','')
ht = findobj(h,'tag',[mfilename '_text']);
delete(ht)
end
% ----------
function [h,ax]=h2hax(handle)
typ = get(handle,'type');
if strcmp(typ,'figure')
h = handle;
ax = findobj(h,'type','axes');
elseif strcmp(typ, 'axes')
h = get(handle,'parent');
ax = handle;
elseif strcmp( get(get(handle,'parent'), 'type'), 'axes' )
ax = get(handle,'parent');
h = get(ax,'parent');
end
http://apps.hi.baidu.com/share/user/41caedc2bda36d61746c6162330a
(1)fix(x) : 截尾取整.
>> fix( [3.12 -3.12])
ans =
3 -3
(2)floor(x):不超过x 的最大整数.(高斯取整)
>> floor( [3.12 -3.12])
ans =
3 -4
(3)ceil(x) : 大于x 的最小整数
>> ceil( [3.12 -3.12])
ans =
4 -3
(4)四舍五入取整
>> round(3.12 -3.12)
ans =
0
>> round([3.12 -3.12])
ans =
3 -3
对于动态显示鼠标的坐标值和像素值,在其他语言如vc,vb中都比较方便,有直接的着方面的函数,那么在matlab图像处理里面又如何实现呢?
具体的实现方法很多,但归结起来就是获取坐标轴的current point 属性值,我这里给出的一个函数是从mathworks 获取柄稍作修改后的结果,相信对做图像处理的朋友有一定的作用。另一个就是自带的pixval函数。谁有不同的实现方法,请多多共享啊!
function dynpoint(arg,h)
% Show the coordinates of a plot dynamically
%
% To start use:
% dynpoint(h)
% where h is a handle to a figure, axes or e.g. line.
%
% To delete use:
% dynpoint('delete',h)
% where h is a handle to a figure, axes or e.g. line.
% (you may also use: dynpoint delete)
%
% There can only be one dynamic plotter in a figure at a time.
%
% Example:
% subplot(211), hline = plot(sin(1:10))
% subplot(212), plot(sin(1:100))
% dynpoint(hline)
% 2002,6.29
if ~exist('arg','var')
arg = gcf;
end
if ~isstr(arg)
handle = arg;
arg = 'init';
end
switch arg
case 'init'
if ~ishandle(handle)
error('h is not a handle')
end
[h,ax] = h2hax(handle);
% delete old dynamic text object
ht = findobj(h,'tag',[mfilename '_text']);
if any(ht)
delete(ht)
end
% text window at the bottom left corner
% text in centred
uicontrol(h,...
'style','text',...
'pos',[2 2 200 15],...
'tag',[mfilename '_text'],...
'userdata',ax(1))
% do the dynamic thing...
set(h,'windowbuttonmotionfcn',[mfilename ' move'])
case 'move'
ht = findobj(gcbf,'tag',[mfilename '_text']);
ax = overobj('axes');
if ~any(ax)
ax = get(ht,'userdata');
end
p = get(ax,'currentpoint');
set(ht,'string',sprintf('(%g, %g)', p(1), p(3)));
case 'delete'
if ~exist('h','var')
h = gcf;
end
[h,ax] = h2hax(h);
set(h,'windowbuttonmotionfcn','')
ht = findobj(h,'tag',[mfilename '_text']);
delete(ht)
end
% ----------
function [h,ax]=h2hax(handle)
typ = get(handle,'type');
if strcmp(typ,'figure')
h = handle;
ax = findobj(h,'type','axes');
elseif strcmp(typ, 'axes')
h = get(handle,'parent');
ax = handle;
elseif strcmp( get(get(handle,'parent'), 'type'), 'axes' )
ax = get(handle,'parent');
h = get(ax,'parent');
end
相关文章推荐
- matlab如何控制坐标轴显示内容,而不改变曲线形状
- matlab 坐标图动画,动态显示数据
- [转]如何在视图中跟随鼠标移动显示曲线坐标
- BCB中如何实时显示鼠标的坐标?---利用定时器
- C# chart,有关如何在鼠标移动到Series上时显示节点及数据 (有待继续更新)
- 如何让Matlab中的Simulink支持中文显示
- winform如何用Timer实现将时间动态显示在窗体上?
- 如何在页面上显示当前时间(动态更新)
- ListView如何动态显示与隐藏headerview,footerview
- 该程序能够获得鼠标的X坐标,显示在文本框中:
- 如何通过动态生成Html灵活实现DataGrid分类统计的界面显示功能
- iOS根据坐标数据点所在的坐标区域来动态显示到可视范围
- 如何使用ajax接受json返回的字符串数组,并动态异步显示到超链接的下面
- jQuery如何让鼠标经过菜单时显示子菜单并且鼠标经过子菜单时子菜单也显示
- MATLAB 调整坐标轴刻度的显示
- 如何显示动态库的的依赖关系
- Matlab获取鼠标坐标值的两种途径
- [Win8]Windows8开发笔记(四):画刷介绍以及如何实现实现歌词动态变色显示
- 脚本如何得到鼠标坐标
- Matlab实现数据的动态显示方法