Pages

Saturday, January 21, 2012

Boundary Fill Algorithm


Flood fill, also called seed fill, is an algorithm that determines the area connected to a given node in a multi-dimensional array. It is used in the "bucket" fill tool of paint programs to determine which parts of a bitmap to fill with color, and in games such as Go and Minesweeper for determining which pieces are cleared. When applied on an image to fill a particular bounded area with color, it is also known as boundary fill.



This is the code discussed in the video.

void boundaryFill4 (int x, int y, int fill, int boundary) {
 int current:
 current = getpixel (x, y);
  if ((current != boundary) && (current != fill)) {
   setcolor (fill);
   setpixel (x, y):
   boundaryFill4 (x+l, y, fill, boundary);
   boundaryFill4 (x-1, y, fill, boundary);
   boundaryFill4 (x, y+l, fill, boundary);
   boundaryFill4 (x, y-1, fill, boundary) ;
 }

2 comments:

  1. The problem i see with your code is that the boundary is not a single point. So int boundary is useless.

    ReplyDelete
  2. This comment has been removed by the author.

    ReplyDelete