How to select a region if we click inside it?

조회 수: 1 (최근 30일)
Meshooo
Meshooo 2014년 1월 8일
댓글: Image Analyst 2016년 10월 24일
Dear all,
I have a binary image same as the one I show here which contains few honeycomb regions connected to each other. Now I want a single honeycomb to be selected when the user makes a left click using the mouse inside the desired honeycomb. Any idea how
to do that?
Any suggestions will be appreciated.
Sincerely, Mueshoo

채택된 답변

Matt J
Matt J 2014년 1월 8일
Use WAITFORBUTTONPRESS and get(gca,'CurrentPoint') to detect the location of the click.
Then use INPOLYGON to detect which honeycomb was selected.
  댓글 수: 3
Matt J
Matt J 2014년 1월 14일
For example the rows of V
V=[0 0 ; 1 0; 0 1]
are vertices of a triangle.
Since (0.1,0.2) lies inside the triangle, this returns true
>>inpolygon(0.1,0.2,V(:,1),V(:,2))
ans =
1
and conversely this returns false,
>> inpolygon(.1,1.2,V(:,1),V(:,2))
ans =
0
Meshooo
Meshooo 2014년 1월 15일
Thank you but still I couldn't do it. Let's say we have many objects in one image as I show here. Now if the user click by the mouse inside any object then this object will remain and all other objects will be removed. Is it possible to do that? Thank you very much for your time.
Mustafa

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

추가 답변 (1개)

Image Analyst
Image Analyst 2014년 1월 15일
Mustafa: Here's how to do it step by step:
  1. invert the image
  2. call imclearborder
  3. label the binary image with bwlabel
  4. call [column, row] = int32(ginput(1)) to let the user click somewhere
  5. get the label with labelNumber = labeledImage(row, column)
  6. extract the object with extractedObject = ismember(labeledImage, labelNumber)
  7. Make it binary again binaryImage = extractedObject > 0;
  8. display it with imshow(binaryImage, []);
See if you can program that up and attach your code if you have problems.
  댓글 수: 6
YEIMY LISETH QUINTANA VILLAMIZAR
YEIMY LISETH QUINTANA VILLAMIZAR 2016년 10월 23일
Can you help me? please,
I need that the program recognize a image of another image, loading a image that is a circle and loading other that is a ellipse.
How I can make that the program recognize that the image is a circle or a ellipse ?
Image Analyst
Image Analyst 2016년 10월 24일
See my shape recognition demo, attached.

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

Community Treasure Hunt

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

Start Hunting!

Translated by