According to the documentation for ginput (type help ginput in the Command Window), this function/command ...gets N points from the current axes and returns the X- and Y-coordinates…. So if you can switch the axes to that of your image, ginput should work for that.
Suppose that I and J are two images that I want to display in two figures:
figure;image(I);axes1Handle=gca;
figure;image(J);axes2Handle=gca;
Two images are displayed, and the axes handles for each are stored in two variables. Now when I type ginput, the cross-hairs naturally appear on the second image. And will continue to do so unless I manually select the other figure OR type the following
which sets the current axis to that of the first image/figure. Now typing ginput brings up the cross-hairs on the first image.
You should be able to do the same in your script. Get the axes of the figure for the image and save it to a local variable. Just prior to using the command ginput switch the current axes to that of the image.
See if this helps. I can't test out your code since I don't have the Image Processing Toolbox.
Best Answer