Manual object counter inside an image

조회 수: 3 (최근 30일)
Ely Raz
Ely Raz 2014년 1월 6일
댓글: Ely Raz 2014년 1월 7일
Hi
How can I program a very simple manual counter on top of an image that I show (GUI). Basically, I wish to load an image to a axes and every time I click the mouse a point and its counting number appears next to it.
Thanks.

채택된 답변

Image Analyst
Image Analyst 2014년 1월 6일
From the help:
[x,y] = ginput gathers an unlimited number of points until you press the Return key.
Put some code in like this (untested)
message = sprintf('Click points.\nHit return when done.');
button = questdlg(message, 'Continue?', 'Yes', 'No', 'Yes');
drawnow; % Refresh screen to get rid of dialog box remnants.
if strcmpi(button, 'No')
return;
end
[x,y] = ginput();
count = length(x);
  댓글 수: 3
Image Analyst
Image Analyst 2014년 1월 6일
편집: Image Analyst 2014년 1월 6일
Only after it's done when you can say
plot(x, y, 'r+', 'MarkerSize', 24, 'LineWidth', 3);
If you want it to mark after each one you'll have to put ginput(1) inside a while loop
% Display an image.
imshow('moon.tif');
hold on;
% Initialize counter.
count = 0;
message = sprintf('Click as many points as you want.\nHit return when done.');
title(message, 'FontSize', 20);
button = questdlg(message, 'Continue?', 'OK', 'Cancel', 'OK');
drawnow; % Refresh screen to get rid of dialog box remnants.
if strcmpi(button, 'Cancel')
return;
end
% Begin loop where user clicks points over display (plot or image or whatever).
while count < 1000 % or whatever failsafe you want.
% User clicks one point. If user types Enter/Return, x is empty.
[x,y] = ginput(1);
if isempty(x)
break;
end
% Put a cross over the point.
plot(x, y, 'r+', 'MarkerSize', 24, 'LineWidth', 3);
% Increment the count.
count = count + 1
% Save coordinates (if desired).
allX(count) = x;
allY(count) = y;
end
Please mark as Accepted if this answers your question.
Ely Raz
Ely Raz 2014년 1월 7일
Hi,
A question about the script above (I click the mouse for marking and enter when I am done). Is it possible to mark by mouse left clicking and when finish mouse right clicking?
Thanks.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Exploration에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by