Jake Sumrican
Jake Sumrican

Reputation: 23

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?

Image that is to be divided into shapes

Upvotes: 0

Views: 417

Answers (2)

Randy
Randy

Reputation: 219

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.

Upvotes: 1

Krease
Krease

Reputation: 16215

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).

Upvotes: 0

Related Questions