• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

algorithm to detect different colored areas in bitmap?

lozina

Lifer
I am not a graphics programmer so I have no idea what terms to use to search for this... but it should be a pretty common algorithm.

I have a bitmap image which has several irregular shaped areas of solid color. Imagine a map of the united states where each state was filled in with a solid unique color. I need to scan such an image and create polygons out of the states.

The ultimate goal is that the program will have a bunch of polygons (or just arrays of vertexes?) which represent each state in the map, so If I display that map on a screen and the user clicks on the map I can figure out what state the user clicked on by testing in which polygon the mouse coordinates fall.

I know there is an easier way to do this, by dynamically getting the pixel at the coordinate and then looking up the pixel's color against a table to match the country but I can't do this for reasons I'll only confuse you with.
 
Search under image processing topics for edge detection algorithms.

Edit: should add, I can't tell if the state thing is just an example, or is your real problem. I also don't know if the application is web or thick client. If your data is really as stable as political boundaries, then it would be a heck of a lot simpler to hand-define a set of polys to encompass the right areas (essentially what a web imagemap is).
 
It is for a 2D application written in C# using XNA.

The state thing is just an example but my real situation is exactly the same. I need to define clickable areas that are accurate so I'd rather not try to hand define polygons for it. Besides the "map" is large so it would take a long time doing it by hand.
 
Here is an article that discusses the exact algorithms I'm looking for, but unfortunately it just has a vague general description of how they actually work and post no code. http://www.geovista.psu.edu/si...99/Gc99/076/gc_076.htm

If you scroll halfway down the page you see a colored map of china, each province in a solid color. Then you see these feint lines traced around each blocky province which represents the line the algorithm traced around them. This is exactly what I need to do. Except its not a geographic map in my case but that doesn't matter.
 
Back
Top