ginput: How to prompt for value after each click?

8 ビュー (過去 30 日間)
Cole
Cole 2014 年 9 月 28 日
編集済み: Image Analyst 2014 年 9 月 29 日
Hi,
I'm making a little program that loads a photo then calls ginput so I can click on a number of features. For each feature, I want to enter an estimated value.
Click Prompt: Enter thickness: Enter Value
Click Prompt:
etc
Is there anyway to do this?
Thanks,
Cole

採用された回答

Image Analyst
Image Analyst 2014 年 9 月 28 日
For the thickness prompt, try inputdlg().
To get the points, try getpts() if you have the Image Processing Toolbox. Or just put
[x,y] = ginput(1)
into a while loop where you break out of the while loop if the user clicks the right mouse button. Try this:
clc;
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
fontSize = 24;
imshow('cameraman.tif');
hold on;
maxAllowablePoints = 5; % Whatever you want.
numPointsClicked = 0;
promptMessage = sprintf('Left click up to %d points.\nRight click when done.', maxAllowablePoints);
titleBarCaption = 'Continue?';
button = questdlg(promptMessage, titleBarCaption, 'Continue', 'Cancel', 'Continue');
if strcmpi(button, 'Cancel')
return;
end
while numPointsClicked < maxAllowablePoints
numPointsClicked = numPointsClicked + 1;
[x(numPointsClicked), y(numPointsClicked), button] = ginput(1)
plot(x(numPointsClicked), y(numPointsClicked), 'r+', 'MarkerSize', 15);
if button == 3
% Exit loop if
break;
end
end
% Print to command window
x
y
msgbox('Done collecting points');

その他の回答 (1 件)

Cole
Cole 2014 年 9 月 28 日
Thanks!
I'll give that a try as well.
After posting the question, I thought of one way to do it. I get the length of X from ginput, then in a loop, I plot X(i),Y(i), prompt to enter a thickness for that value then delete that plot marker and move on to the next. Seems to work okay.
  1 件のコメント
Image Analyst
Image Analyst 2014 年 9 月 28 日
編集済み: Image Analyst 2014 年 9 月 29 日
There is also a getpts() in the Image Processing Toolbox you may want to take a look at.

サインインしてコメントする。

カテゴリ

Find more on Visual Exploration in Help Center and File Exchange

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by