0

Imagine I have two point arrays. One of them is an open polygon, which looks like this.

Image 1

Xes are black dots and points ('.') - white ones.

The second point array contains a closed polygon:

Image 2

I need the name of an algorithm, which allows me to determine whether a given point array is a closed polygon or an open one. I need this information to determine, whether I can flood filll it (I cannot flood fill the first example, but I can flood fill the second one).

What is the algorithm called, which allows me to distinguish between the two types of polygons?

Update 1 (10.10.2015 10:05 MSK): I need to distinguish between closed and open polygons in order to prevent flood fill errors.

A flood fill errors, is when I apply flood fill to an open polygon like

.....
..XXX
.X..X
X...X

and end up with a completely filled grid:

XXXXX
XXXXX
XXXXX
XXXXX

My original idea was to

  1. take the polygon,
  2. check, if it's open or closed and
  3. if it's closed, apply flood fill.

Now, I could do it differently:

  1. Flood fill the polygon.
  2. If the entire grid is filled, then it's an open one, otherwise (at least one point in the grid after flood fill is white), it's a closed one.

If there is a way to avoid doing flood fill for determining, whether a polygon is open or closed, please tell me.

Glory to Russia
  • 17,289
  • 56
  • 182
  • 325
  • 2
    I would call it a "flood fill algorithm". That is, if you flood fill starting at a random corner and inspect every pixel, then if you find a not-filled one, it is on the inside of a closed shape, else it's an open shape. – Jongware Oct 09 '15 at 20:38
  • there are several ways to do that, but i can't recall the names of any and i don't have my copy of "Digital Image Processing, by Gonzales and Woods" handy. one easy way is to apply the fill and then check the corners: if any are not border or unfilled, then the polygon is open and you need to revert the fill. Another way is to pick any intersect of the perimeter, then trace it by examining the adjacent NSEW pixels for more line (you don't seem to need city-block distance above 1, or in other words, no NE/SW boundries). Keep tracing until you arrive at a previous coord or run out of line. bingo – dandavis Oct 09 '15 at 20:41
  • @Jongware See my update 1. If there is a way to do it without flood filling, please tell me. – Glory to Russia Oct 10 '15 at 07:36
  • The error you describe in your update may be because you are filling with the same color as the border, and so you cannot determine anymore if a pixel was changed or was there initially. If you fill with another color, you won't have that problem - the fill color should be unique. – Jongware Oct 10 '15 at 09:23

1 Answers1

0

I don't have any experience with this but while I was researching something else I found this and thought it might be helpful for you:

http://www.cs.tufts.edu/~sarasu/courses/comp175-2009fa/pdf/comp175-05-region-filling.pdf

The slides mention 3 different algorithms:

  • X-intersection array algorithm
  • Edge list algorithm
  • Pineda’s algorithm
DhawalV
  • 188
  • 1
  • 2
  • 16