简体   繁体   中英

How to define a complex shape?

For this image, I am trying to define a shape for each "territory". How would I accomplish doing this?

将被分成形状的图像

I'm not sure how you want to implement, but this generic approach should work:

  • Discretely separate the regions in your image using boundary lines, so they no longer tough each other. (Using morphological erodes, for example.)
  • Do a "connected component" (CC) operation on the images to generate a different label for each region's pixels (1, 2, 3, ...). You can probably find some code online to do this, but it's easy to write your own CC function.
  • When a user clicks on a region, map the mouse's X/Y coordinate onto your labeled image to find the region label under that point, and report the label.

Hopefully you can define the shapes of your territories as a series of points - ie (x1, y1), (x2, y2), etc, then you can use one of the hit testing algorithms defined here: How can I determine whether a 2D Point is within a Polygon? (several great answers there, general enough that you could adapt the concepts to fit your needs).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM