matlab - 如何显示坐标和使用ginput

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

我似乎无法让我的图像显示鼠标光标的坐标,同时也无法使用 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

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

最佳答案

如果您键入 edit ginput 并滚动到第 238 行,您会看到

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

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

确实,在 impixelinfoval(impixelinfo 使用的函数)中,我们在第 83 行附近找到:

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

那么奇怪的是:点击 4 个点后它是如何重置的?

这个魔法是由 ginput 的第 222 行实现的:

initialState.uisuspendState = uisuspend(fig);

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

%initialState.uisuspendState = uisuspend(fig);

并保存 ginput,然后重新执行整个操作,您会看到您想要的行为。

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

关于matlab - 如何显示坐标和使用ginput,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11457242/

相关文章:

matlab - 在Matlab中使一个函数返回多个值

c++ - 在 C 代码中为 Matlab/LabView 接口(interface)创建 DLL 包装器

Java jTable 来自 ArrayList 对象的数据并通过其他方法更新

javascript - 鼠标移动时出现,静止时消失的导航栏

c++ - Opengl 鼠标相机问题 (gluLookAt)

matlab - 在 Matlab 中构造分段符号函数

matlab - 按降序对 MATLAB 数组进行排序

python - 如何使用 Kivy 制作工具提示?

python - 等待按钮点击

java - 如何让图像跟随鼠标移动?