User input from clicking on a position on a diagram/image

42 次查看(过去 30 天)
Hello,
I was wondering whether it was possible to get a use an image to get an input for matlab.
Take a football pitch for example. Would it be possible to get a birds eye image of a pitch and split it up into a grid, the user pics a particular square in the grid which then returns a x,y co-ordinate to matlab.
Its sort of possible using VBA in excel, however I'm not as handy with Matlab as I am excel.
Thanks for your time.

采纳的回答

Image Analyst
Image Analyst 2012-3-12
Yes. Use ginput() to get a point. Then convert that x,y point into calibrated units using your knowledge of how many pixels correspond to how many real world units (such as meters).
  3 个评论
RAGAV K
RAGAV K 2012-7-9
I did the same, below is the piece of code:
axis ij;
axis manual;
[m n] = size(d1); %%d1 is the image which I want to display
axis([0 m 0 n])
imshow(d1);
coordinates_input = round(ginput(1));
But when I checked the value of coordinates_input it was [25.5000,91.5000];
How do I change this so that I get pixel position in whole numbers?
Image Analyst
Image Analyst 2012-7-9
That will happen if your image doesn't have unit magnification. For example if it's magnified so that one image pixel takes up 9 screen pixels, you can click "in the middle of a pixel" and the coordinates will give you that fractional location. Rounding, as you've done, seems like a reasonable way to return the pixel closest to where the user clicked. See this demo to understand:
d1 = rand(40);
axis ij;
axis manual;
[m n] = size(d1); %%d1 is the image which I want to display
axis([0 m 0 n])
imshow(d1);
zoom(8)
% Enlarge figure to full screen.
set(gcf, 'units','normalized','outerposition',[0 0.5 1 0.5]);
coordinates_input = ginput(1)
row = round(coordinates_input(2));
column = round(coordinates_input(1));
fprintf('You clicked on coordinates (row, column) = (%f, %f)\nWhich is the pixel in row %d, column %d\n', ...
coordinates_input(1), coordinates_input(2), row, column);

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Convert Image Type 的更多信息

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by