trant said:
[...]
Basically, I read a map image which is filled with several uniquely colored
homogeneous regions. Think maybe a map of a state where all it's counties are
colored with unique solid colors.
[...]
Again, the right approach would be to write an algorithm that can actually
trace the borders of those counties from the input index map, but I just
can't figure that out.
My first thought: assuming you're of average intelligence or better (and
if you've figured out how to program and post to this newsgroup, surely
you are), it is implausible to me that you simply can't figure out any
of the algorithms suggested previously.
I haven't double-checked, but my recollection is that in at least one
case, the entire implementation was even provided in some form
(pseudo-code or some actual programming language). But even without
such explicit guidance, with some effort you should be able to figure
things out.
My second thought: when you describe the problem as a "map", are you
literally talking about an actual geo-political map of cities, states,
countries, etc? If so, then it is practically guaranteed that you could
in fact just obtain the data already in a practical format for dealing
the areas as regions (i.e. a polygon). Having to convert from a
color-coded map to a polygon or other format yourself seems like a lot
of extra, unnecessary work.
All that said, if you do insist on using the Region class, examining
each pixel individually, a couple of suggestions:
– Unless you know that each region on the map is a completely unique
color (many maps reuse colors, simply ensuring that adjacent regions
aren't the same color), you still have a problem identifying individual
regions, rather than getting some Region instance that contains two
discontiguous areas.
– If you do know that each region on the map has a unique color, then
IMHO it would be better to enumerate every pixel by row and column,
using a Dictionary<Color, Region> to quickly map from color to a
specific region instance you're building for that color.
– In any case, you definitely should learn about the
Bitmap.LockBits() or BitmapSource.CopyPixels() methods, either of which
you can use to obtain a raw data form of the image data, which will be
MUCH faster to examine than using GetPixel(). GetPixel() is easier to
use, but it's so much slower that the investment in learning how to
examine the pixel data directly when it's in an array is worthwhile.
Pete