[Insight-users] How to flood fill contours?

Ofri Sadowsky ofri@cs.jhu.edu
Mon, 03 Feb 2003 10:33:28 -0500


--------------EFCE636B69035FD6E8B5E8B3
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

It all depends on how hard you plan to work to solve this problem, but
here are a few clues.

1. If all your contours are connected, closed, and simple curves, I
think that there is not problem. When you reach a white pixel, its west,
northwest, north, and northeast neighbors must be black. Its east
neighbor may be white, in which case if any of the pixels that you
check, in that order, is black, then it must be an inner pixel. If the
east neighbor is black, then the south neighbor must be an inner pixel.
There are, however, a few exception cases, such as:

  a) If there are single and insulated white pixels, the rule above does
not apply. This is easy to check.
  b) If the thickness of the contour is more than one pixel, you may
encounter something like this:

---
-+-
++-

  where + is white and - is black. In this case, none of your three
pixel is an inner one. You can check for this condition by verifying
that of the three southern neighbors, neither SW and S, nor S and SE are
white.

2. If you fall upon a contour which is not closed, then flood-fill will
overflow, regardless of you choice of an inner pixel, simply because
there are no inner pixels. There are several ways to ensure that all the
contours are closed, such as:
  a) Use a zero-crossing-gradient criterion to decide on contour points,
or something like Canny edge-detector.
  b) Follow the chain of contour points to make sure that eventually you
go to the beginning.

The first option may not suit your choice of edge-detecting filter. The
second should require more programming work. There may be other ways to
handle this, but let's start with the simpler ones.

Regards,

Ofri.

Parag Chandra wrote:

> Hi,I'm trying to flood fill contours in a binary image, and I've been
> using ConnectedThresholdImageFilter with pretty good results so far.
> The trouble I have now is in identifying seed points for certain
> tricky types of contours. What I've been doing is scanning the image
> from left to right, top to bottom, and when I encounter a white pixel,
> I simply take the first black pixel southeast, south, or southwest of
> that white pixel and give that as a seedpoint. That of course doesn't
> work if the white pixel I've just encountered happens to be the very
> tip of a contour and the southern black pixel I've identified as the
> seed actually lies outside the contour. Can someone recommend an
> approach for automatically identifying a seed point that lies inside
> the contour? Thanks. -Parag Chandra

--------------EFCE636B69035FD6E8B5E8B3
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit

<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<body bgcolor="#FFFFFF">
It all depends on how hard you plan to work to solve this problem, but
here are a few clues.
<p>1. If all your contours are connected, closed, and simple curves, I
think that there is not problem. When you reach a white pixel, its west,
northwest, north, and northeast neighbors must be black. Its east neighbor
may be white, in which case if any of the pixels that you check, in that
order, is black, then it must be an inner pixel. If the east neighbor is
black, then the south neighbor must be an inner pixel. There are, however,
a few exception cases, such as:
<p>&nbsp; a) If there are single and insulated white pixels, the rule above
does not apply. This is easy to check.
<br>&nbsp; b)&nbsp;If the thickness of the contour is more than one pixel,
you may encounter something like this:
<p>---
<br>-+-
<br>++-
<p>&nbsp; where +&nbsp;is white and - is black. In this case, none of your
three pixel is an inner one. You can check for this condition by verifying
that of the three southern neighbors, neither SW and S, nor S&nbsp;and
SE&nbsp;are white.
<p>2. If you fall upon a contour which is not closed, then flood-fill will
overflow, regardless of you choice of an inner pixel, simply because there
are no inner pixels. There are several ways to ensure that all the contours
are closed, such as:
<br>&nbsp; a)&nbsp;Use a zero-crossing-gradient criterion to decide on
contour points, or something like Canny edge-detector.
<br>&nbsp; b)&nbsp;Follow the chain of contour points to make sure that
eventually you go to the beginning.
<p>The first option may not suit your choice of edge-detecting filter.
The second should require more programming work. There may be other ways
to handle this, but let's start with the simpler ones.
<p>Regards,
<p>Ofri.
<p>Parag Chandra wrote:
<blockquote TYPE=CITE><style></style>
<font face="Arial"><font size=-1>Hi,</font></font><font face="Arial"><font size=-1>I'm
trying to flood fill contours in a binary image, and I've been using ConnectedThresholdImageFilter
with pretty good results so far. The trouble I have now is in identifying
seed points for certain tricky types of contours. What I've been doing
is scanning the image from left to right, top to bottom, and when I encounter
a white pixel, I simply take the first black pixel southeast, south, or
southwest of that white pixel and give that as a seedpoint. That of course
doesn't work if the white pixel I've just encountered happens to be the
very tip of a contour and the southern black pixel I've identified as the
seed actually lies outside the contour. Can someone recommend an approach
for automatically identifying a seed point that lies inside the contour?
Thanks.</font></font>&nbsp;<font face="Arial"><font size=-1>-Parag Chandra</font></font></blockquote>

</body>
</html>

--------------EFCE636B69035FD6E8B5E8B3--