How to capture coordinates (x,y) through event click mouse

  • Follow


Hi,

Can I help me with the next situation:

I need catch the point coordinates (x,y) from an image displayed into a Matlab Figure, and store this coordinates in two variables (i.e., X1,Y1) through event click mouse, anyone help me with this situation.

Thanks for your attention.

Regards. 
0
Reply Jose 11/28/2010 11:38:04 PM

Look up the function called ginput() in the help.
0
Reply ImageAnalyst 11/28/2010 11:49:11 PM


ImageAnalyst <imageanalyst@mailinator.com> wrote in message <4a6de9e0-0520-4bd4-b072-c1c1a8a82657@39g2000yqa.googlegroups.com>...
> Look up the function called ginput() in the help.

Hi,

I trying as follows:

I = imread('\Lena.bmp','bmp');
figure(1);
imshow(I);
[xc,yc] = ginput(1);

However, the result is not favorable:

??? Error using ==> setappdata
Invalid object handle.

Error in ==> uisuspend at 63
        setappdata(fig,'UISuspendActive',true);

Error in ==> ginput at 93
   state = uisuspend(fig);

Error in ==> reg_of_int at 11
[xc,yc] = ginput;

Can you help me. Thanks.
0
Reply Jose 11/29/2010 12:52:03 AM

Does this work for you?
You might have to change it to read in your own image, and you might
have to join lines if the newsreader split long lines into two lines.

clc;	% Clear command window.
clear;	% Delete all variables.
close all;	% Close all figure windows except those created by imtool.
imtool close all;	% Close all figure windows created by imtool.
workspace;	% Make sure the workspace panel is showing.
fontSize = 20;

% Change the current folder to the folder of this m-file.
if(~isdeployed)
        cd(fileparts(which(mfilename)));
end

% Read in a standard MATLAB gray scale demo image.
folder = 'C:\Program Files\MATLAB\R2010b\toolbox\images\imdemos';
baseFileName = 'cameraman.tif';
fullFileName = fullfile(folder, baseFileName);
grayImage = imread(fullFileName);
% Get the dimensions of the image.  numberOfColorBands should be = 1.
[rows columns numberOfColorBands] = size(grayImage);
% Display the original gray scale image.
imshow(grayImage, []);
title('Original Grayscale Image', 'FontSize', fontSize);
% Enlarge figure to full screen.
set(gcf, 'Position', get(0,'Screensize'));
set(gcf,'name','Demo by ImageAnalyst','numbertitle','off')

uiwait(msgbox('Left-Click once in the image'));

numberOfPointsToClick = 1;
[xc yc] = ginput(numberOfPointsToClick)

message=sprintf('You clicked at (x,y)=(%.1f,%.1f)',xc,yc);
fprintf(1,'%s\n',message);
uiwait(msgbox(message));
0
Reply ImageAnalyst 11/29/2010 1:06:51 AM

ImageAnalyst <imageanalyst@mailinator.com> wrote in message <03000224-4e18-4d3b-b2d1-4d71ab52e5f2@e10g2000yqh.googlegroups.com>...
> Does this work for you?
> You might have to change it to read in your own image, and you might
> have to join lines if the newsreader split long lines into two lines.
> 
> clc;	% Clear command window.
> clear;	% Delete all variables.
> close all;	% Close all figure windows except those created by imtool.
> imtool close all;	% Close all figure windows created by imtool.
> workspace;	% Make sure the workspace panel is showing.
> fontSize = 20;
> 
> % Change the current folder to the folder of this m-file.
> if(~isdeployed)
>         cd(fileparts(which(mfilename)));
> end
> 
> % Read in a standard MATLAB gray scale demo image.
> folder = 'C:\Program Files\MATLAB\R2010b\toolbox\images\imdemos';
> baseFileName = 'cameraman.tif';
> fullFileName = fullfile(folder, baseFileName);
> grayImage = imread(fullFileName);
> % Get the dimensions of the image.  numberOfColorBands should be = 1.
> [rows columns numberOfColorBands] = size(grayImage);
> % Display the original gray scale image.
> imshow(grayImage, []);
> title('Original Grayscale Image', 'FontSize', fontSize);
> % Enlarge figure to full screen.
> set(gcf, 'Position', get(0,'Screensize'));
> set(gcf,'name','Demo by ImageAnalyst','numbertitle','off')
> 
> uiwait(msgbox('Left-Click once in the image'));
> 
> numberOfPointsToClick = 1;
> [xc yc] = ginput(numberOfPointsToClick)
> 
> message=sprintf('You clicked at (x,y)=(%.1f,%.1f)',xc,yc);
> fprintf(1,'%s\n',message);
> uiwait(msgbox(message));

Hi,

Thanks for the detailed explication. But a strange reason, the above code showed the same error, however, I restart the MATLAB Version 7.4.0.287 (R2007a), and the code was run without problem.

Thank you very much.

Best Regards.
0
Reply Jose 11/29/2010 2:15:05 AM

You must have clicked somewhere, while you were stepping through it in
the debugger, to change the current figure (gcf) from your image to
something else, perhaps to the MATLAB window itself rather than the
figure window containing your image.
0
Reply ImageAnalyst 11/29/2010 2:56:08 AM

5 Replies
957 Views

(page loaded in 0.078 seconds)

Similiar Articles:













7/26/2012 1:55:10 AM


Reply: