Marking where one clicked with ginput

51 ビュー (過去 30 日間)
Guillermo
Guillermo 2011 年 7 月 25 日
コメント済み: Mohamed Nedal 2019 年 5 月 13 日
Hi Community,
I was wondering if it were possible to be able to know where one clicked on an image while using ginput(n), i.e. having a red dot over the area where I clicked so that I later am able to remember where it is that I already clicked in case I "zoned out" while clicking.
Thanks in advance.

採用された回答

Nathan Greco
Nathan Greco 2011 年 7 月 25 日
I did something similar to this when measuring diameters of soot particles. I would frequently get lost as to where I last clicked, so I decided to create some text where I clicked, stating what was first clicked and what was second clicked.
[x,y] = ginput(1);
h1 = text(x,y,'1', ...
'HorizontalAlignment','center', ...
'Color', [1 0 0], ...
'FontSize',8);
%etc...
%to delete text:
delete(h1);
%etc...
  1 件のコメント
Melanie Lafanechere
Melanie Lafanechere 2016 年 12 月 28 日
Hello, I have a similar question. Is it possible to populate the coordinates from the ginput with a picture, if so, how? I have a 6x8 grid image and I'm trying to populate the squares with a counter image (.bmp).
Thank you!

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

その他の回答 (3 件)

Alice Liu
Alice Liu 2015 年 6 月 30 日
Here's my code for n clicks:
I = imread('yourimage.tif')
figure, imshow(I)
n = 10
coordinates = zeroes(n,2);
hold on
for i=1:n
[x, y] = ginput(1);
coordinates(i,:) = [x, y];
plot(coordinates(:,1), coordinates(:,2), '+');
end
hold off
Hope this helped!
  1 件のコメント
Mohamed Nedal
Mohamed Nedal 2019 年 5 月 13 日
Hi, I tried your code with the a FIT file and the function imagesc() as the following:
A = fitsread('R_7.fit');
C = max(A);
f = imagesc(A); colorbar
n = 10;
coordinates = zeros(n,2);
hold on
for i = 1:n
[x, y] = ginput(1);
coordinates(i,:) = [x, y];
plot(coordinates(:,1), coordinates(:,2), 'MarkerSize', 10, '*');
end
hold off
But it gives me this error:
Error using plot
Data must be a single matrix Y or a list of pairs X,Y.
Error in read_interact (line 13)
plot(coordinates(:,1),coordinates(:,2),'MarkerSize',10,'*');
And when I remove the 'MarkerSize' attribute I found that the marker color changes each time I click. How can I keep the marker color without changing and how to increase its size in this case?
Thanks in advance

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


Paulo Silva
Paulo Silva 2011 年 7 月 25 日
hold on
[x,y]=ginput(1)
plot(x,y,'r')
  2 件のコメント
Guillermo
Guillermo 2011 年 7 月 25 日
Sweet, thanks for the speedy response. Now i have another question to add to this one, if i want to clear the lines, how do i do it without reloading the image?
Nathan Greco
Nathan Greco 2011 年 7 月 25 日
h = plot(x,y,'r'); %plots point (or line if x/y are vectors)
delete(h); %deletes plotted items from current plot

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


Mohamed Nedal
Mohamed Nedal 2019 年 5 月 13 日
Hi, when I use imagesc() function with plot() function it doesn't display the dots on the image shown by imagesc().
In this case, what's your suggestion?
Please check the attached file and the code here:
A = fitsread('R_7.fit');
C = max(A);
f = imagesc(A); colorbar
hold on
[x,y] = ginput(10);
plot(x,y,'r');

カテゴリ

Help Center および File ExchangeData Exploration についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by