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.
댓글 수: 0
채택된 답변
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
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
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 Center 및 File Exchange에서 Convert Image Type에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!