[Insight-users] How to flood fill contours?

Parag Chandra pchandra@radonc.unc.edu
Mon, 3 Feb 2003 12:58:40 -0500


This is a multi-part message in MIME format.

------=_NextPart_000_0039_01C2CB83.F991EE40
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Thanks for the suggestion. The approach I am taking is to flood fill =
from a point that I know is not inside any contour, which for my =
purposes will always be the upper left corner of the image. Then I =
simply scan left to right, top to bottom, looking for a black pixel, =
which is now guaranteed to be inside a contour. The pixel just to the =
left of that will be the contour edge, which will tell me the fill color =
I should use, and I simply flood fill from the black pixel I just found.

This brings me to another question: Is the ConnectedThresholdImageFilter =
4-connected or 8-connected?
  ----- Original Message -----=20
  From: Ofri Sadowsky=20
  To: Parag Chandra=20
  Cc: ITK Mailing List=20
  Sent: Monday, February 03, 2003 10:33 AM
  Subject: Re: [Insight-users] How to flood fill contours?


  It all depends on how hard you plan to work to solve this problem, but =
here are a few clues.=20
  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:=20

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

  ---=20
  -+-=20
  ++-=20

    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.=20

  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:=20
    a) Use a zero-crossing-gradient criterion to decide on contour =
points, or something like Canny edge-detector.=20
    b) Follow the chain of contour points to make sure that eventually =
you go to the beginning.=20

  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.=20

  Regards,=20

  Ofri.=20

  Parag Chandra wrote:=20

    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
------=_NextPart_000_0039_01C2CB83.F991EE40
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2800.1126" name=3DGENERATOR></HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>Thanks for the suggestion. The approach =
I am taking=20
is to flood fill from a point that I know is not inside any contour, =
which for=20
my purposes will always be the upper left corner of the image. Then I =
simply=20
scan left to right, top to bottom, looking for a black pixel, which is =
now=20
guaranteed to be inside a contour. The&nbsp;pixel just to the left of =
that will=20
be the contour edge, which will tell me the fill color I should use, and =
I=20
simply flood fill from the black pixel I just found.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>This brings me to another question: Is =
the=20
ConnectedThresholdImageFilter 4-connected or 8-connected?</FONT></DIV>
<BLOCKQUOTE dir=3Dltr=20
style=3D"PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; =
BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
  <DIV style=3D"FONT: 10pt arial">----- Original Message ----- </DIV>
  <DIV=20
  style=3D"BACKGROUND: #e4e4e4; FONT: 10pt arial; font-color: =
black"><B>From:</B>=20
  <A title=3Dofri@cs.jhu.edu href=3D"mailto:ofri@cs.jhu.edu">Ofri =
Sadowsky</A>=20
</DIV>
  <DIV style=3D"FONT: 10pt arial"><B>To:</B> <A =
title=3Dpchandra@radonc.unc.edu=20
  href=3D"mailto:pchandra@radonc.unc.edu">Parag Chandra</A> </DIV>
  <DIV style=3D"FONT: 10pt arial"><B>Cc:</B> <A=20
  title=3Dinsight-users@public.kitware.com=20
  href=3D"mailto:insight-users@public.kitware.com">ITK Mailing List</A> =
</DIV>
  <DIV style=3D"FONT: 10pt arial"><B>Sent:</B> Monday, February 03, 2003 =
10:33=20
  AM</DIV>
  <DIV style=3D"FONT: 10pt arial"><B>Subject:</B> Re: [Insight-users] =
How to flood=20
  fill contours?</DIV>
  <DIV><BR></DIV>It all depends on how hard you plan to work to solve =
this=20
  problem, but here are a few clues.=20
  <P>1. If all your contours are connected, closed, and simple curves, I =
think=20
  that there is not problem. When you reach a white pixel, its west, =
northwest,=20
  north, and northeast neighbors must be black. Its east neighbor may be =
white,=20
  in which case if any of the pixels that you check, in that order, is =
black,=20
  then it must be an inner pixel. If the east neighbor is black, then =
the south=20
  neighbor must be an inner pixel. There are, however, a few exception =
cases,=20
  such as:=20
  <P>&nbsp; a) If there are single and insulated white pixels, the rule =
above=20
  does not apply. This is easy to check. <BR>&nbsp; b)&nbsp;If the =
thickness of=20
  the contour is more than one pixel, you may encounter something like =
this:=20
  <P>--- <BR>-+- <BR>++-=20
  <P>&nbsp; where +&nbsp;is white and - is black. In this case, none of =
your=20
  three pixel is an inner one. You can check for this condition by =
verifying=20
  that of the three southern neighbors, neither SW and S, nor S&nbsp;and =

  SE&nbsp;are white.=20
  <P>2. If you fall upon a contour which is not closed, then flood-fill =
will=20
  overflow, regardless of you choice of an inner pixel, simply because =
there are=20
  no inner pixels. There are several ways to ensure that all the =
contours are=20
  closed, such as: <BR>&nbsp; a)&nbsp;Use a zero-crossing-gradient =
criterion to=20
  decide on contour points, or something like Canny edge-detector. =
<BR>&nbsp;=20
  b)&nbsp;Follow the chain of contour points to make sure that =
eventually you go=20
  to the beginning.=20
  <P>The first option may not suit your choice of edge-detecting filter. =
The=20
  second should require more programming work. There may be other ways =
to handle=20
  this, but let's start with the simpler ones.=20
  <P>Regards,=20
  <P>Ofri.=20
  <P>Parag Chandra wrote:=20
  <BLOCKQUOTE TYPE=3D"CITE">
    <STYLE></STYLE>
    <FONT face=3DArial><FONT size=3D-1>Hi,</FONT></FONT><FONT =
face=3DArial><FONT=20
    size=3D-1>I'm trying to flood fill contours in a binary image, and =
I've been=20
    using ConnectedThresholdImageFilter with pretty good results so far. =
The=20
    trouble I have now is in identifying seed points for certain tricky =
types of=20
    contours. What I've been doing is scanning the image from left to =
right, top=20
    to bottom, and when I encounter a white pixel, I simply take the =
first black=20
    pixel southeast, south, or southwest of that white pixel and give =
that as a=20
    seedpoint. That of course doesn't work if the white pixel I've just=20
    encountered happens to be the very tip of a contour and the southern =
black=20
    pixel I've identified as the seed actually lies outside the contour. =
Can=20
    someone recommend an approach for automatically identifying a seed =
point=20
    that lies inside the contour? Thanks.</FONT></FONT>&nbsp;<FONT=20
    face=3DArial><FONT size=3D-1>-Parag=20
Chandra</FONT></FONT></BLOCKQUOTE></BLOCKQUOTE></BODY></HTML>

------=_NextPart_000_0039_01C2CB83.F991EE40--