0

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

Jake Sumrican
  • 23
  • 2
  • 9
  • This seems like a good starting point: http://docs.oracle.com/javase/tutorial/2d/advanced/complexshapes.html - are you trying to draw it, or do hit detection, or something else? – Krease Nov 15 '12 at 00:04
  • What have you tried? What ideas do you have, that we might be able to improve upon? – wattostudios Nov 15 '12 at 01:33
  • @Chris: I'm trying to have something happen when the user clicks inside a territory. I don't know if there is a better way to do it :P – Jake Sumrican Nov 15 '12 at 02:33
  • @WATTO Studios: I don't have any ideas on how to do this, as the regions can't easily be defined as a combination of simple shapes. As a last resort, I might have a button in the middle that the user can click on, but that doesn't seem very creative to me. – Jake Sumrican Nov 15 '12 at 02:36
  • The code on [Smoothing a jagged path](http://stackoverflow.com/questions/7218309/smoothing-a-jagged-path) will provide an edge between two colors, but it is not 'per pixel' smooth (see thread for details). Given your image is so large, it might not be a problem. But also, if you can devote the time to figuring how to take out those 'bumpy bits', add it as an answer to my original question to get a 'tick'. ;) – Andrew Thompson Nov 15 '12 at 02:58

2 Answers2

1

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.
KatieK
  • 13,586
  • 17
  • 76
  • 90
Randy
  • 219
  • 1
  • 3
0

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

Community
  • 1
  • 1
Krease
  • 15,805
  • 8
  • 54
  • 86