Figure 11 A region-growing algorithm for use with images containing zeroes and a value

1. Given an image g with m rows and n columns
      g(i,j) for i=1,m j=1,n
      g(i,j) = value for object
              = 0 for background

2. set g_label=2 this is the label value

3.    for (i=0; i<m; i++)
            scan ith row
            for (j=0; j<n; j++)
                 check jth element
                 stack_empty = true
                 if g(i,j) == value
                       label_and_check_neighbor(g(i,j),g_label)
                 while stack_empty = false do
                       pop element (i,j) off the stack
                       label_and_check_neighbor(g(i,j),g_label)
                 end while
                 g_label = g_label + 1
            end of checking jth element
      end of scanning ith row

4. The End

                  --------------------------------------

procedure label_and_check_neighbor(g(r,e), g_label)
      g(r,e) = g_label
      for (R=r-1; r<=r+1; R++)
            for (E=e-1; e<=e+1; e++)
                 if g(R,E) == value then
                       push (R,E) onto the stack
                       stack_empty = false
                 end if
            end loop over E
      end loop over R
end procedure label_and_check_neighbor