Clear Filters
Clear Filters

Counting polygon vertices while polygon is drawn

3 views (last 30 days)
Is there a way to count the number of polygon vertices specified in impoly(), roipoly(), or roipolyold() while the polygon is being drawn? I'd like to add a counter to my GUI to let the user know how many points they've selected while drawing a polygon. This way, they can make sure to have the minimum number of points required for each polygon so that the program performs optimally. Thus far,I have only been able to accomplish creating such a counter using ginput and a while loop. However, I really don't like that ginput cannot be constrained to an axes object. I'd prefer to limit my user from clicking outside the desired area (i.e. the image). Anyhow, I would greatly appreciate any suggestions/comments. Thanks!

Answers (1)

Image Analyst
Image Analyst on 10 Apr 2013
Not that I know of. You could put something like imline() in a loop and build it up just one line at a time. But how many vertices are required? If there are just a few (4-8), why not just count them when they're all done and alert them only then if there are not enough?
  1 Comment
Susan
Susan on 10 Apr 2013
The required number of vertices is 15 per polygon. And there may be anywhere from 1-3 polygons drawn per image. I like how ginput() returns what button was pressed so that you can have it in a while loop and end the selection when the right mouse button is pressed. I really wish that imline did that. If so, it would be perfect. Thanks for the suggestion.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!