Jackerd
Jackerd

Reputation: 53

WPF: Finding all closed areas in an image (C# or even VB)

I am working on a simple coloring book for children with physical limitations. Teachers will be able to insert a picture in the program composed of only closed areas. I then need to analyze the image and find all closed areas (the places the child will be able to color). I need to do this because all areas that can be painted will glow up one after the other. I think I can accomplish this with a floodfill so I need a point (X,Y coordinate) inside every closed area.

Anyone ever did something like this? Some tips or source code available?

Many thanks!

Upvotes: 0

Views: 1081

Answers (1)

Mike Caron
Mike Caron

Reputation: 14561

I don't have much experience with WPF per se, but I would probably use an algorithm like this:

First, I am assuming the image is strictly monochrome. That is, there are only pure black (line) and pure white (colourable area) pixels.

  1. Convert the image to true-colour
  2. Examine the Top-Left pixel.
  3. If this pixel is white, do a flood fill with a new unique colour
  4. Move one-pixel to the right (if out of bounds, move down one and all the way to the left)
  5. Go to 3

Now, every area in the image has a different colour.

Upvotes: 2

Related Questions