Question

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

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.

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top