How to display coordinates and use ginput

后端 未结 1 816
我寻月下人不归
我寻月下人不归 2021-01-12 19:52

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 followin

相关标签:
1条回答
  • 2021-01-12 20:14

    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());
    

    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.

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

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

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

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

    initialState.uisuspendState = uisuspend(fig);
    

    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);
    

    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.

    0 讨论(0)
提交回复
热议问题