【问题标题】:get the coordinate of a pixel by clicking on it in matlab通过在matlab中单击它来获取像素的坐标
【发布时间】:2012-11-26 19:08:22
【问题描述】:

这是我第一次创建 matlab GUI。

我想通过使用matlab单击图像中的像素来获取它的坐标,我创建了一个包含轴的Matlab GUI,并且轴通过以下代码包含图像:

function axes1_CreateFcn(hObject, eventdata, handles)
     axes(hObject);
     I = imread('cameraman.tif');
     imshow(I);

对于ButtonDownFcn,获取点击像素的坐标:

function axes1_ButtonDownFcn(hObject, eventdata, handles)
     handles.xy1 = round(get(handles.axes1,'Currentpoint'));
     x1 = handles.xy1(1,1);
     y1 = handles.xy1(1,2);

问题是当我点击图片时ButtonDownFcn 没有被调用,但是当我从CreateFcn 函数中删除代码时,ButtonDownFcn 被调用。

如何在显示图片的同时保持ButtonDownFcn工作?

谢谢,

【问题讨论】:

  • 您需要以编程方式处理它们还是只想查看它们?

标签: image matlab user-interface coordinates axes


【解决方案1】:

需要设置这些功能。像这样的东西会起作用:

set(hFigure,'ButtonDownFcn', @axes1_ButtonDownFcn);

【讨论】:

    【解决方案2】:

    这仅仅是因为当您在 Axes 上执行函数 imshow 时,Matlab GUI 的奇怪行为会重置 Axes 的属性。

    您会看到 image 和 surf 命令悄悄地更改坐标区属性的副作用。 [通过 Mathworks:here]

    试试这个代码来显示你的图片:

    function axes1_CreateFcn(hObject, eventdata, handles) 
       axes(hObject);
       tag = get(hObject,'Tag');
       I = imread('cameraman.tif');
       imshow(I);
       set(hObject,'Tag',tag);
       set(hFigure,'ButtonDownFcn', @axes1_ButtonDownFcn);
    end
    

    如果您只想查看坐标,请使用Data Cursor 工具,将其从Toolbar Editor 添加到您的GUI,然后您可以使用它在Axes 绘图或图像上导航并显示来自点击位置的信息,以及您甚至可以更改其操作代码。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-04-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多