找回密码
 注册
Simdroid-非首页
查看: 431|回复: 8

【讨论】如何动态显示鼠标的坐标值和图像像素值

[复制链接]
发表于 2002-9-7 10:01:20 | 显示全部楼层 |阅读模式 来自 北京
对于动态显示鼠标的坐标值和像素值,在其他语言如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
jd1-3 该用户已被删除
发表于 2002-9-9 15:32:18 | 显示全部楼层 来自 广东广州
提示: 作者被禁止或删除 内容自动屏蔽
 楼主| 发表于 2002-9-9 16:04:03 | 显示全部楼层 来自 北京

Re:【讨论】如何动态显示鼠标的坐标值和图像像素值

第一次运行可以直接用dynpoint, or dynpoint(gcf) ;
另外,不知你的图像的数据格式是什么?这一点我见一你看看程序,可以根据你的
图像格式做个修改。因为我这个是为了我自己的使用而作的。
jd1-3 该用户已被删除
发表于 2002-9-9 16:25:20 | 显示全部楼层 来自 广东广州
提示: 作者被禁止或删除 内容自动屏蔽
 楼主| 发表于 2002-9-9 17:00:31 | 显示全部楼层 来自 北京

Re:【讨论】如何动态显示鼠标的坐标值和图像像素值

DICOM图像格式我还没有用过,他需要在程序中作一些处理(主要是在获取像素值的地方)。你看看吧!
jd1-3 该用户已被删除
发表于 2002-9-9 17:05:54 | 显示全部楼层 来自 广东广州
提示: 作者被禁止或删除 内容自动屏蔽
 楼主| 发表于 2002-9-9 17:17:45 | 显示全部楼层 来自 北京

Re:【讨论】如何动态显示鼠标的坐标值和图像像素值

我现在看了看,原来这个程序是我的半成品,它只能显示坐标值的。你再运行一下,应该没有问题的!对于dicom数据,因为它是int16数据,对图像工具箱的某些函数是不支持的如imcrop需要特小心。
jd1-3 该用户已被删除
发表于 2002-9-10 00:48:12 | 显示全部楼层 来自 广东广州
提示: 作者被禁止或删除 内容自动屏蔽
 楼主| 发表于 2002-9-10 02:04:35 | 显示全部楼层 来自 北京

Re:【讨论】如何动态显示鼠标的坐标值和图像像素值

这是因为你的程序有错。数组索引不正确!老兄以后多检查你的程序再问问题会好些!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|小黑屋|联系我们|仿真互动网 ( 京ICP备15048925号-7 )

GMT+8, 2024-5-5 10:14 , Processed in 0.041206 second(s), 15 queries , Gzip On, MemCache On.

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表