Azzera filtri
Azzera filtri

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

42 visualizzazioni (ultimi 30 giorni)
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.

Risposta accettata

Image Analyst
Image Analyst il 12 Mar 2012
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 Commenti
RAGAV K
RAGAV K il 9 Lug 2012
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 il 9 Lug 2012
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);

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Convert Image Type in Help Center e File Exchange

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by