How to display coordinates and use ginput
Asked Answered
L

1

6

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.

Laxation answered 12/7, 2012 at 17:24 Comment(0)
C
6

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.

Cimmerian answered 12/7, 2012 at 18:55 Comment(5)
Thanks you for your reply, unfortunately our ginput functions must be very different, as none of the lines you mentioned are in my ginput function. I tried commenting this out: state = uisuspend(fig) This appears at line 92. This did not work however.Laxation
What version of Matlab do you have?Cimmerian
Ah. I have R2012a. Apparently they changed it a lot in the past 2 years. Anyway, the reasoning should still hold. Do you always re-execute all commands after saving?Cimmerian
Not quite sure what you mean, but I save the edits, and then rerun my script. But no worries, thanks so much for the help I will go through the ginput with a fine tooth comb, or just get the R2012a ginput function from a friend. Thanks again!Laxation
With R2010a comment these 2 lines: Lines 92 & 183.Laxation

© 2022 - 2024 — McMap. All rights reserved.