How to detect left mouse clicks within an area of an image

조회 수: 10 (최근 30일)
Hi everyone,
I am trying to display an image and what I want to do is to record in the variable h if the user clicks within an area of the image (h=1 if the users clicks within that area and h=0 if not) and save in the variable n the number of left-mouse clicks that the user makes within that area.
The image is immage.png and the three points that determine the "area" commented above are: pointA, pointB and pointC
I have the following code:
h=0;
n=0;
imshow('immage.png')
axis off
hold on
pointA=[200,145];
pointB=[210,159];
pointC=[300,162];
plot(pointA(1),pointA(2),'ro');
plot(pointB(1),pointB(2),'ro');
plot(pointC(1),pointC(2),'ro');
Which results in the following:
How can I achieve that? I have been searching but I didn`t find anything
Thank you very much

채택된 답변

Image Analyst
Image Analyst 2021년 7월 18일
Did youi try to use drawpoint()?
Try my attached demo that counts the number of points a user clicks on.
  댓글 수: 2
ErikJon Pérez Mardaras
ErikJon Pérez Mardaras 2021년 7월 18일
Thank you! It is very useful
But is there any way of doing that without "drawing" in the image the point where the user clicks?
Is there any way of just updating the variable h and n but without appearing in the image any drawing of the dot?
Thank you very much
ErikJon Pérez Mardaras
ErikJon Pérez Mardaras 2021년 7월 18일
Thank you very much
It can be done like that:
p=drawpoint('Visible','off');
For more information I have checked this site

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Convert Image Type에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by