MATLAb-----7--------如何动态显示鼠标的坐标值和图像像素值
来源:互联网 发布:python升级到2.7 pip 编辑:程序博客网 时间:2024/05/21 14:46
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 =
(2)floor(x):不超过x 的最大整数.(高斯取整)
>> floor( [3.12 -3.12])
ans =
(3)ceil(x) : 大于x 的最小整数
>> ceil( [3.12 -3.12])
ans =
(4)四舍五入取整
>> round(3.12 -3.12)
ans =
>> round([3.12 -3.12])
ans =
具体的实现方法很多,但归结起来就是获取坐标轴的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-----7--------如何动态显示鼠标的坐标值和图像像素值
- 利用OpenCV鼠标事件设置函数setMouseCallback显示图像像素的RGB、HSV和坐标值!
- MFC中用OpenCV显示图像,并跟踪鼠标显示图像的坐标与像素
- 用opencv读取图像的每个像素值,鼠标点击获取每一个点,并显示像素
- opencv动态显示图像像素值
- OPENCV系列(一)读取图像中任意点的像素值,并显示坐标
- MFC 以图像大小打开并显示图像,鼠标左击显示像素坐标
- 实时获取窗口鼠标坐标及像素值的方法
- 加载图像并点击读取坐标值和像素值
- matlab gui matlab gui 鼠标点击显示图像颜色值
- 定位图像中像素坐标的方法(matlab)
- 图像指定坐标点的各通道像素值提取
- matlab中如何得到图像的坐标
- matlab中如何得到图像的坐标
- opencv利用鼠标获取图像的像素值
- opencv利用鼠标获取图像的像素值
- opencv利用鼠标获取图像的像素值
- 对于灰度图像中同一个像素,MATLAB和Photoshop的灰度值不同
- POJ_1061 青蛙的约会 解题报告
- u-boot-2011.03移植系列专题汇总
- css:级连样式表
- 有关C++中的 placement new
- GDAL综合整理--9:其它
- MATLAb-----7--------如何动态显示鼠标的坐标值和图像像素值
- C++和C#中的回调函数
- OPENJUDGE 2815 城堡问题
- bit位的设置和清零
- php根据IP获取地址位置,并在谷歌地图上显示出来
- Qt之相关error总结
- poj 2019 Cornfields
- 解决requestFeature() must be called before adding content错误
- 空白符,不仅仅只有空格