【问题标题】:How to display coordinates and use ginput如何显示坐标和使用ginput
【发布时间】:2012-07-12 12:32:22
【问题描述】:

我似乎无法让我的图像显示鼠标光标的坐标,同时也无法使用 ginput 来存储点。

我目前正在尝试以下方法:

MriHotrod = imread('Image.bmp');
Fig = figure('Name','BobDole'),...
    imshow(Image, 'InitialMagnification', 250)

axis on
impixelinfo

Image_1 = ginput(4)

close BobDole

ginput 仍然有效,但 impixelinfo 保持不变

Pixel Info = (X, Y) Pixel Value

我知道一些解决此问题的方法,但它们涉及函数。这似乎是一个相当简单的问题,可以避免使用函数。

【问题讨论】:

    标签: matlab user-interface mousemove matlab-figure cursor-position


    【解决方案1】:

    如果你输入 edit ginput 并滚动到第 238 行,你会看到

    % Adding this to enable automatic updating of currentpoint on the figure 
    set(fig,'WindowButtonMotionFcn',@(o,e) dummy());
    

    也就是说,ginput 在图中设置了一个WindowButtonMotionFcn。我的猜测是impixelinfo 也使用了这个函数,所以一旦调用ginput 它就会被禁用。

    确实,在impixelinfovalimpixelinfo 使用的函数)中,我们可以在第 83 行找到:

    callbackID = iptaddcallback(hFig,'WindowButtonMotionFcn', @displayPixelInfo);
    

    然后奇怪的是:点击 4 点后它是如何重置的?

    这个魔法是由ginput 的第 222 行完成的:

    initialState.uisuspendState = uisuspend(fig);
    

    显然,uisuspend 是一个未记录的函数,用于暂停任何预先存在的 WindowButton* 函数,以便稍后重置它们。所以,如果你注释掉这一行

    %initialState.uisuspendState = uisuspend(fig);
    

    并保存ginput,然后重新做整个事情,你会看到你想要的行为。

    您还将看到为什么这些功能首先会被暂停 - 由于我不太明白的原因,当启用两个这样的功能时,一切都会变得异常缓慢。

    【讨论】:

    • 感谢您的回复,不幸的是我们的 ginput 函数必须非常不同,因为您提到的行都没有在我的 ginput 函数中。我尝试对此进行注释: state = uisuspend(fig) 这出现在第 92 行。但是这不起作用。
    • 你有什么版本的 Matlab?
    • 啊。我有 R2012a。显然他们在过去的两年里改变了很多。无论如何,推理应该仍然成立。保存后是否总是重新执行所有命令?
    • 不太清楚你的意思,但我保存了编辑,然后重新运行我的脚本。不过不用担心,非常感谢您的帮助,我将使用细齿梳完成 ginput,或者只是从朋友那里获得 R2012a ginput 功能。再次感谢!
    • 使用 R2010a 注释这两行:第 92 行和第 183 行。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-23
    • 1970-01-01
    • 1970-01-01
    • 2013-06-09
    • 1970-01-01
    相关资源
    最近更新 更多