Difference Between Flood-fill and Boundary-fill Algorithm

Analysis of AlgorithmsAlgorithmsMisc Algorithms

In this post, we will understand the differences between flood fill algorithm and boundary fill algorithm. They are area-filling algorithms, and they can be differentiated based on whether a random pixel has the region's original colour or not.

Flood-fill algorithm

  • It is also known as seed fill algorithm.
  • It calculates the area that is connected to a given node with respect to a multi-dimensional array.
  • It works by filling up or recolouring a specific area that contains different colours in the inside part, and hence, the boundary of the image.
  • It is represented by a picture that has a neighbourhood which has borders and has distinct colour regions.
  • The specific interior colour can be replaced, in order to pain these parts.
  • The memory consumption is high.
  • It is a comparatively simple algorithm.
  • It has the ability to process image that contains more than one boundary colours.
  • It is comparatively slower in comparison to boundary-fill algorithm.
  • A random colour can be used to paint the interior part, and the old pixel is replaced with the new one.
  • It is an efficient algorithm.

Two methods can be used to create multiple boundaries by connecting pixels.

  • 4-connected way: In this method, the pixel can have four neighbours at maximum. These would be placed at positions- left, right, above and below the current pixel.
  • 8-connected way: In this method, the pixel can have 8 neighbours at maximum. The neighbouring positions are checked against the four diagonal pixels.

Boundary-fill algorithm

  • When the boundary contains single colour, the algorithm continues in the outward direction, pixel by pixel until the boundary colour is found.
  • It is implemented within interactive painting packages, where the inside points can be easily chosen.
  • The algorithm begins by accepting the coordinates of an inside point (x, y), a boundary colour and fill colour which become the input.
  • From point (x, y), the algorithm checks its neighbouring locations to determine whether or not they are a part of the boundary colour.
  • If they are not from the boundary colour, then it is painted with the fill colour, and the adjacent pixels are tested against the same condition.
  • This process ends when all the pixels up to the boundary colour are checked.
  • The area is defined with a single colour.
  • The memory consumption is lower.
  • It is quick in comparison to flood-fill algorithm.
  • It is complicated in comparison to flood-fill algorithm.
  • It can process images that contain a single boundary colour.
Published on 02-Mar-2021 05:09:13