Scanning inputs from mouse in two images

Hi Folks, I would like to display two images and then use mouse clicks to scan coordinates of certain feature points in those two images. Following is what I have, but it does not seem to get mouse focus on first image.
imageDir = '/home/ankitc/images/2cameraViewImages/tripod1';
images = imageSet(imageDir);
I1 = read(images, 1);
I2 = read(images, 2);
figure(1);
imshow(I1);
title('1st image');
figure(2);
imshow(I2);
title('2nd image');
count = 1;
while (count < 50)
[x1,y1] = ginput(1);
[x2,y2] = ginput(2);
count = count + 1;
end
I am able to cross hairs on figure 2, and do get mouse click inputs in [x2,y2] but nothing seems to come in [x1,y1]. I am not able to move the focus/cross-hairs to figure 1. My intent is to first scan a mouse click over fig1 and then scan second click from over figure 2.
Thanks,

Answers (1)

Ankit - according to ginput, [x,y] = ginput(n) enables you to identify n points from the current axes and returns the... The reason that you can never get the cross-hairs on the first image is that ginput always focusses on the current axes which corresponds to your second image (the last one created). You will need to set the current axes before each call to ginput. For example, suppose we save the handle to each axes of each figure as
figure(1);
imshow(I1);
hAxes1 = gca;
title('1st image');
figure(2);
imshow(I2);
hAxes2 = gca;
title('2nd image');
We use gca to get the current axes. Then, just prior to calling ginput we set the current axes as
while (count < 50)
axes(hAxes1);
[x1,y1] = ginput(1);
axes(hAxes2);
[x2,y2] = ginput(2)
count = count + 1;
end
Try the above and see what happens!

Asked:

on 29 Jun 2016

Answered:

on 30 Jun 2016

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!