如何显示坐标并使用ginput [英] How to display coordinates and use ginput

查看:442
本文介绍了如何显示坐标并使用ginput的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I cannot seem to get my image to display the coordinates of my mouse cursor, and also use ginput to store points at the same time.

我目前正在尝试以下操作:

I currently am trying the following:

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

axis on
impixelinfo

Image_1 = ginput(4)

close BobDole

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

The ginput still works, but the impixelinfo stays constant

Pixel Info = (X, Y) Pixel Value

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

I am aware of some methods of getting around this, but they involve functions. This seems like a rather simple problem that can avoid the use of functions.

推荐答案

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

If you type edit ginput and scroll to line 238-ish, you'll see

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

换句话说,ginput在图中设置了WindowButtonMotionFcn.我的猜测是impixelinfo也使用此功能,因此一旦调用ginput,它将被禁用.

In other words, ginput sets a WindowButtonMotionFcn in the figure. My guess is that impixelinfo uses this function as well, so it gets disabled as soon as ginput is called.

实际上,在impixelinfoval(impixelinfo使用的函数)中,我们可以在第83行找到:

Indeed, in impixelinfoval (a function used by impixelinfo) we find around line 83:

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

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

The odd thing is then: how does it get reset after you click 4 points?

这种魔力是通过ginput的222-ish行实现的:

This magic is accomplished by line 222-ish of ginput:

initialState.uisuspendState = uisuspend(fig);

显然,uisuspend是一个未公开的小功能,用于挂起任何先前存在的WindowButton*函数,以便稍后对其进行重置.所以,如果您注释掉这一行

Apparently, uisuspend is a little undocumented function that is used to suspend any pre-existing WindowButton* functions, in order to reset them later. So, if you comment out this line

%initialState.uisuspendState = uisuspend(fig);

并保存ginput,然后重新执行整个操作,您将看到所需的行为.

and save ginput, and re-do the whole thing, you see the behavior you want.

您还将首先了解为什么暂停这些功能-出于我不太了解的原因,启用两个这样的功能后,一切都会变得非常缓慢.

You will also see why these functions get suspended in the first place -- For reasons I do not quite understand, everything gets unworkably slow when two such functions are enabled.

这篇关于如何显示坐标并使用ginput的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆